Compile Error: Labels must appear before a loop

BlitzMax Forums/BlitzMax Beginners Area/Compile Error: Labels must appear before a loop


Compile Error: Labels must appear before a loop or DefData statement



...any idea's what this means? code in question is a relatively complex nest of if statements with various goto's pointing to this single label. no other labels exist in the project, and as far as i know all syntax is legal...

Function check_particle()
	Const x_less = grid_x - 1
	Const x_plus = grid_x + 1
	Const y_less = grid_y - 1
	Const y_plus = grid_y + 1
	If grid_x > 0 Then
		If xy_position[x_less, grid_y] > 30 Then
			colour_chosen = xy_colour[x_less, grid_y]
			Goto check_particle_b
		End If
		If grid_y > 0 Then
			If xy_position[x_less, y_less] > 30 Then
				colour_chosen = xy_colour[x_less, y_less]
				Goto check_particle_b
			End If
		End If
		If grid_y < height Then
			If xy_position[x_less, y_plus] > 30 Then
				colour_chosen = xy_colour[x_less, y_plus]
				Goto check_particle_b
			End If
		End If
	End If
	If grid_x < width Then
		If xy_position[x_plus, grid_y] > 30 Then
			colour_chosen = xy_colour[x_plus, grid_y]
			Goto check_particle_b
		End If
		If grid_y > 0 Then
			If xy_position[x_plus, y_less] > 30 Then
				colour_chosen = xy_colour[x_plus, y_less]
				Goto check_particle_b
			End If
		End If
	End If
	If grid_y > 0 Then
		If xy_position[grid_x, y_less] > 30 Then
			colour_chosen = xy_colour[grid_x, y_less]
			Goto check_particle
		End If
	End If
	If grid_y < height Then
		If xy_position[grid_x, y_plus] > 30 Then
			colour_chosen = xy_colour[grid_x, y_plus]
			Goto check_particle_b
		End If
	End If
	Return

	#check_particle_b

	If grid_x > 0 Then
		If xy_position[x_less, grid_y] = 0 Then
			place_particle()
			Return
		End If
		If grid_y > 0 Then
			If xy_position[x_less, y_less] = 0 Then
				place_particle()
				Return
			End If
		End If
		If grid_y < height Then
			If xy_position[x_less, y_plus] = 0 Then
				place_particle()
				Return
			End If
		End If
	End If
	If grid_x < width Then
		If xy_position[x_plus, grid_y] = 0 Then
			place_particle()
			Return
		End If
		If grid_y > 0 Then
			If xy_position(x_plus, y_less) = 0 Then
				place_particle()
				Return
			End If
		End If
		If grid_y < height Then
			If xy_position[x_plus, y_plus] = 0 Then
				place_particle()
				Return
			End If
		End If
	End If
	If grid_y > 0 Then
		If xy_position[grid_x, y_less] = 0 Then
			place_particle()
			Return
		End If
	End If
	If grid_y < height Then
		If xy_position[grid_x, y_plus] = 0 Then
			place_particle()
			Return
		End If
	End If
	Return
End Function


are you using strict mode?

...any idea's what this means?
No, but I'm guessing it has something to do with your return statement.

Is there any paricular reason you're not using Else and 2 seperate functions here?


are you using strict mode?



...yes, does this alter anything? you got me interested so i commented it out and the assembler errored out on "case default" - my bad, shouldn't have left "case" in there. fixing that it now complains about my const's not being constant (which is odd...) unless i bring strict back, then it goes back to complaining about my label... hmm?

mikkel: hi there! respected you ever since your work in blitzmax (lol am i the only one sad enough to read the credits in the back of a manual???). never thought i'd meat you on a forum though...

anyhoo, to be honest i'm not sure what you mean by using seperate functions - due to the deprication of gosub i've had to change a fair amount to this structure, but its still about the simplest i could think of. in its original form i did indeed use seperate routines, but to keep from having to globally declare those statics i thought it best to merge the two. do you have a simpler solution?

the algorithm btw, is much like that of the classic "game of life", where a particle is only born if the surrounding particles are adequate. this function simply checks the surrounding particles (its been so long since my original implementation of it that these days i have no idea what exactly its looking for, lol. i really should get into the habit of commenting my code...).

cheers.

woo!

spotted a typo, one of my goto's was pointing to check_particle rather than check_particle_b. changing that, commenting out strict, and replacing the const's with local's gets the project running!

results aren't as expected though, and after a few seconds execution ends. seems i must have made some oopsies porting that function accross... will have got a few checks backwards somewhere =).

hmm... spotted what i assumed to be the only whoopsy in the project, fixed that and no change was made to the output. can't spot anything else...

whats more worrying though, is i noticed i wasn't running with debug enabled: enabled that and attempted to run. screen went black and mouse or keyboard interaction didn't end execution! all i could do was ctrl+backspace to restart the x server and log back in again... darent run it now lol!

[EDIT]
wasn't a one off, just did it again! appears x is crashing out for some reason, somewhere after mousemove()

current code:

Rem
	Written in BlitzMax 1.08 on GNU Linux.

	AuroraSaver - Aurora northern lights screensaver by Freefornow.co.uk
	Copyright (C) 2005 Richard Grant
	EMail: <email removed for web crawlers>
	Address: <address removed for web crawlers>

	This program is free software; you can redistribute it And/Or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, Or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY Or FITNESS For A PARTICULAR PURPOSE.  See the
	GNU General Public License For more details.

	You should have received a copy of the GNU General Public License
	along with this program; If Not, write To the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
EndRem

Framework BRL.glMax2D
Import BRL.Random
Import BRL.StandardIO
Import BRL.System

'Strict

Local width = 400, height = 300, mode = 16

If Not GraphicsModeExists(400, 300, 16) Then
	If GraphicsModeExists(400, 300, 24) Then
		mode = 24
	Else
		width = 800
		height = 600
		If Not GraphicsModeExists(800, 600, 16) Then
			If GraphicsModeExists(800, 600, 24) Then
				mode = 24
			Else
				RuntimeError "Cannot initialise a suitable resolution; Execution has terminated!"
				End
			End If
		End If
	End If
End If

' Global Ints
Global grid_x = 0, grid_y = 0
Global one_fourth_width = width / 4, one_fourth_height = height / 4
Global three_fourth_width = one_fourth_width * 3, three_fourth_height = one_fourth_height * 3
Global half_width = width / 2, half_height = height / 2
Global loops = 0, finished_fading = 0, colour = 0

' Global Strings
Global colour_chosen:String = "g"

' Global Arrays
Global xy_colour:String[width, height], xy_position[width, height]

SeedRnd MilliSecs()

Repeat
	grid_x = Rnd(0, width)
	grid_y = Rnd(0, height)
Until grid_x < one_fourth_width Or grid_x > three_fourth_width Or grid_y < one_fourth_height Or grid_y > three_fourth_height

place_particle()

Graphics width, height, mode

HideMouse()
MoveMouse(half_width, half_height)

While MouseX() = 0 Or MouseY() = 0
Wend

While (GetChar() + MouseHit(1) + MouseHit(2) + MouseHit(3) + MouseZ() = 0) And MouseX() = half_width And MouseY() = half_height
	If loops = 1000 Then
		finished_fading = 1
		For grid_x = 0 To width
			For grid_y = 0 To height
				If xy_position[grid_x, grid_y] > 0 Then
					finished_fading = 0
					If xy_position[grid_x, grid_y] < 6 Then
						xy_position[grid_x, grid_y] = 0
					Else
						xy_position[grid_x, grid_y] = xy_position[grid_x, grid_y] - 5
					End If
					draw_particle()
				End If
			Next
		Next
		If finished_fading = 1 Then
			loops = 0
			Cls
			generate_particle()
		End If
	Else
		loops = loops + 1
		If loops Mod 150 = 0 Then generate_particle()
		For grid_x = 0 To width
			For grid_y = 0 To height
				If xy_position[grid_x, grid_y] = 0 Then
					If Int(Rnd(0, 3)) = 0 Then check_particle()
				Else
					xy_position[grid_x, grid_y] = xy_position[grid_x, grid_y] - 1
					draw_particle()
				End If
			Next
		Next
	End If
	FlushMem
	Flip
Wend
End

Function check_particle()
	Local x_less = grid_x - 1
	Local x_plus = grid_x + 1
	Local y_less = grid_y - 1
	Local y_plus = grid_y + 1
	If grid_x > 0 Then
		If xy_position[x_less, grid_y] > 30 Then
			colour_chosen = xy_colour[x_less, grid_y]
			Goto check_particle_b
		End If
		If grid_y > 0 Then
			If xy_position[x_less, y_less] > 30 Then
				colour_chosen = xy_colour[x_less, y_less]
				Goto check_particle_b
			End If
		End If
		If grid_y < height Then
			If xy_position[x_less, y_plus] > 30 Then
				colour_chosen = xy_colour[x_less, y_plus]
				Goto check_particle_b
			End If
		End If
	End If
	If grid_x < width Then
		If xy_position[x_plus, grid_y] > 30 Then
			colour_chosen = xy_colour[x_plus, grid_y]
			Goto check_particle_b
		End If
		If grid_y > 0 Then
			If xy_position[x_plus, y_less] > 30 Then
				colour_chosen = xy_colour[x_plus, y_less]
				Goto check_particle_b
			End If
		End If
		If grid_y < height Then
			If xy_position[x_plus, y_plus] > 30 Then
				colour_chosen = xy_colour[x_plus, y_plus]
				Goto check_particle_b
			End If
		End If
	End If
	If grid_y > 0 Then
		If xy_position[grid_x, y_less] > 30 Then
			colour_chosen = xy_colour[grid_x, y_less]
			Goto check_particle_b
		End If
	End If
	If grid_y < height Then
		If xy_position[grid_x, y_plus] > 30 Then
			colour_chosen = xy_colour[grid_x, y_plus]
			Goto check_particle_b
		End If
	End If
	Return

	#check_particle_b

	If grid_x > 0 Then
		If xy_position[x_less, grid_y] = 0 Then
			place_particle()
			Return
		End If
		If grid_y > 0 Then
			If xy_position[x_less, y_less] = 0 Then
				place_particle()
				Return
			End If
		End If
		If grid_y < height Then
			If xy_position[x_less, y_plus] = 0 Then
				place_particle()
				Return
			End If
		End If
	End If
	If grid_x < width Then
		If xy_position[x_plus, grid_y] = 0 Then
			place_particle()
			Return
		End If
		If grid_y > 0 Then
			If xy_position(x_plus, y_less) = 0 Then
				place_particle()
				Return
			End If
		End If
		If grid_y < height Then
			If xy_position[x_plus, y_plus] = 0 Then
				place_particle()
				Return
			End If
		End If
	End If
	If grid_y > 0 Then
		If xy_position[grid_x, y_less] = 0 Then
			place_particle()
			Return
		End If
	End If
	If grid_y < height Then
		If xy_position[grid_x, y_plus] = 0 Then
			place_particle()
			Return
		End If
	End If
End Function

Function place_particle()
	xy_position[grid_x, grid_y] = 100
	xy_colour[grid_x, grid_y] = colour_chosen
End Function

Function draw_particle()
	Select xy_colour[grid_x, grid_y]
		Case "g"
			SetColor(0, xy_position[grid_x, grid_y], 0)
		Case "r"
			SetColor(xy_position[grid_x, grid_y], 0, 0)
		Case "y"
			SetColor(xy_position[grid_x, grid_y], xy_position[grid_x, grid_y], 0)
	End Select
	DrawRect(grid_x - 1, grid_y - 1, 2, 2)
End Function

Function generate_particle()
	Repeat
		grid_x = Rnd(0, width)
		grid_y = Rnd(0, height)
	Until grid_x < one_fourth_width Or grid_x > three_fourth_width Or grid_y < one_fourth_height Or grid_y > three_fourth_height
	If xy_position[grid_x, grid_y] = 0 Then
		colour = Rnd(0, 11)
		Select True
			Case colour <= 5
				colour_chosen = "g"
			Case colour >= 6 And colour <=9
				colour_chosen = "r"
			Default
				colour_chosen = "y"
		End Select
		place_particle()
	End If
End Function


EH???

i'm beginning to ge the feeling the compiler itself is buggy now!

if i change the graphics mode to ANYTHING other than 400x300, the project doesn't even attempt to run! yet if i create a new project i can use whatever mode i like!

how can this be???

wahay! a little reading up suggested goto was depricated if using strict mode, so i seperated into 2 functions and strict mode started telling me of a few typo's. fixed them, altered the arrays a little, and voila all is working!

took more work than i expected to port this thing over, but its finally running and i take it all back - can't blame a "buggy compiler" now hehe.

cheers guys. current working code is below if interested. not quite a screensaver yet though as i need to find a way to read o/s specific params passed when launching a screensaver... and currently i only know of win32 params (/c, -c, /p, -p, etc.).

Rem
	Written in BlitzMax 1.08 on GNU Linux.

	AuroraSaver - Aurora northern lights screensaver by Freefornow.co.uk
	Copyright (C) 2005 Richard Grant
	EMail: <email removed for web crawlers>
	Address: <address removed for web crawlers>

	This program is free software; you can redistribute it And/Or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, Or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY Or FITNESS For A PARTICULAR PURPOSE.  See the
	GNU General Public License For more details.

	You should have received a copy of the GNU General Public License
	along with this program; If Not, write To the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
EndRem

Framework BRL.glMax2D
Import BRL.Random
Import BRL.StandardIO
Import BRL.System

Strict

Global width = 400, height = 300

Local mode = 16

If Not GraphicsModeExists(400, 300, 16)
	If GraphicsModeExists(400, 300, 24)
		mode = 24
	Else
		width = 800
		height = 600
		If Not GraphicsModeExists(800, 600, 16)
			If GraphicsModeExists(800, 600, 24)
				mode = 24
			Else
				RuntimeError "Cannot initialise a suitable resolution; Execution has terminated!"
				End
			EndIf
		EndIf
	EndIf
EndIf

Global grid_x = 0, grid_y = 0
Global one_fourth_width = width / 4, one_fourth_height = height / 4
Global three_fourth_width = one_fourth_width * 3, three_fourth_height = one_fourth_height * 3
Global half_width = width / 2, half_height = height / 2
Global x_plus = 0, x_less = 0, y_plus = 0, y_less = 0
Global loops = 0, finished_fading = 0, colour = 0

Global colour_chosen:String = "g"

Global xy_colour:String[width + 1, height + 1], xy_position[width + 1, height + 1]

SeedRnd MilliSecs()

Repeat
	grid_x = Rnd(0, width)
	grid_y = Rnd(0, height)
Until grid_x < one_fourth_width Or grid_x > three_fourth_width Or grid_y < one_fourth_height Or grid_y > three_fourth_height

place_particle()

Graphics width, height, mode

HideMouse()
MoveMouse(half_width, half_height)

While MouseX() = 0 Or MouseY() = 0
Wend

While (GetChar() + MouseHit(1) + MouseHit(2) + MouseHit(3) + MouseZ() = 0) And MouseX() = half_width And MouseY() = half_height
	If loops = 1000
		finished_fading = 1
		For grid_x = 0 To width
			For grid_y = 0 To height
				If xy_position[grid_x, grid_y] > 0
					finished_fading = 0
					If xy_position[grid_x, grid_y] < 6
						xy_position[grid_x, grid_y] = 0
					Else
						xy_position[grid_x, grid_y] = xy_position[grid_x, grid_y] - 5
					EndIf
					draw_particle()
				EndIf
			Next
		Next
		If finished_fading = 1
			loops = 0
			Cls
			generate_particle()
		EndIf
	Else
		loops = loops + 1
		If loops Mod 150 = 0 Then generate_particle()
		For grid_x = 0 To width
			For grid_y = 0 To height
				If xy_position[grid_x, grid_y] = 0
					If Int(Rnd(0, 3)) = 0 Then check_particle()
				Else
					xy_position[grid_x, grid_y] = xy_position[grid_x, grid_y] - 1
					draw_particle()
				EndIf
			Next
		Next
	EndIf
	FlushMem
	Flip
Wend
End

Function check_particle()
	x_less = grid_x - 1
	x_plus = grid_x + 1
	y_less = grid_y - 1
	y_plus = grid_y + 1
	If grid_x > 0
		If xy_position[x_less, grid_y] > 30
			colour_chosen = xy_colour[x_less, grid_y]
			check_particle_b()
			Return
		EndIf
		If grid_y > 0
			If xy_position[x_less, y_less] > 30
				colour_chosen = xy_colour[x_less, y_less]
				check_particle_b()
				Return
			EndIf
		EndIf
		If grid_y < height
			If xy_position[x_less, y_plus] > 30
				colour_chosen = xy_colour[x_less, y_plus]
				check_particle_b()
				Return
			EndIf
		EndIf
	EndIf
	If grid_x < width
		If xy_position[x_plus, grid_y] > 30
			colour_chosen = xy_colour[x_plus, grid_y]
			check_particle_b()
			Return
		EndIf
		If grid_y > 0
			If xy_position[x_plus, y_less] > 30
				colour_chosen = xy_colour[x_plus, y_less]
				check_particle_b()
				Return
			EndIf
		EndIf
		If grid_y < height
			If xy_position[x_plus, y_plus] > 30
				colour_chosen = xy_colour[x_plus, y_plus]
				check_particle_b()
				Return
			EndIf
		EndIf
	EndIf
	If grid_y > 0
		If xy_position[grid_x, y_less] > 30
			colour_chosen = xy_colour[grid_x, y_less]
			check_particle_b()
			Return
		EndIf
	EndIf
	If grid_y < height
		If xy_position[grid_x, y_plus] > 30
			colour_chosen = xy_colour[grid_x, y_plus]
			check_particle_b()
			Return
		EndIf
	EndIf
EndFunction

Function check_particle_b()
	If grid_x > 0
		If xy_position[x_less, grid_y] = 0
			place_particle()
			Return
		EndIf
		If grid_y > 0
			If xy_position[x_less, y_less] = 0
				place_particle()
				Return
			EndIf
		EndIf
		If grid_y < height
			If xy_position[x_less, y_plus] = 0
				place_particle()
				Return
			EndIf
		EndIf
	EndIf
	If grid_x < width
		If xy_position[x_plus, grid_y] = 0
			place_particle()
			Return
		EndIf
		If grid_y > 0
			If xy_position[x_plus, y_less] = 0
				place_particle()
				Return
			EndIf
		EndIf
		If grid_y < height
			If xy_position[x_plus, y_plus] = 0
				place_particle()
				Return
			EndIf
		EndIf
	EndIf
	If grid_y > 0
		If xy_position[grid_x, y_less] = 0
			place_particle()
			Return
		EndIf
	EndIf
	If grid_y < height
		If xy_position[grid_x, y_plus] = 0
			place_particle()
			Return
		EndIf
	EndIf
EndFunction

Function place_particle()
	xy_position[grid_x, grid_y] = 100
	xy_colour[grid_x, grid_y] = colour_chosen
EndFunction

Function draw_particle()
	Select xy_colour[grid_x, grid_y]
		Case "g"
			SetColor(0, xy_position[grid_x, grid_y], 0)
		Case "r"
			SetColor(xy_position[grid_x, grid_y], 0, 0)
		Case "y"
			SetColor(xy_position[grid_x, grid_y], xy_position[grid_x, grid_y], 0)
	EndSelect
	DrawRect(grid_x - 1, grid_y - 1, 2, 2)
EndFunction

Function generate_particle()
	Repeat
		grid_x = Rnd(0, width)
		grid_y = Rnd(0, height)
	Until grid_x < one_fourth_width Or grid_x > three_fourth_width Or grid_y < one_fourth_height Or grid_y > three_fourth_height
	If xy_position[grid_x, grid_y] = 0
		colour = Rnd(0, 11)
		Select True
			Case colour <= 5
				colour_chosen = "g"
			Case colour >= 6 And colour <=9
				colour_chosen = "r"
			Default
				colour_chosen = "y"
		EndSelect
		place_particle()
	EndIf
EndFunction