Page 1 of 1

Procedure giving a syntax error

Posted: Wed Jun 19, 2013 11:06 am
by BASICBasher
Hey,
I'm a little puzzled by a error that I've been getting trying to pass a structure as an argument.

I created the following procedure to read groups of properties about a sprite from a configuration file.

Code: Select all

Procedure GSprite_ReadGroup(Name.s, GroupData.GSprite_ActionData)
	PreferenceGroup(Name)
	If BoolPrefs("Used")
		GroupData\Frames = ValPrefs("Frames")
		GroupData\HasDirections = BoolenPrefs("HasDirections")
		If BoolPrefs("Tiled")
			GroupData\XTile = ValPrefs("XTile")
			GroupData\YTile = ValPrefs("YTile")
		EndIf		
	EndIf
EndProcedure
However, when I try to compiler the program, I simply get the error "Syntax Error" with the first line of the procedure highlighted. "BoolPrefs" and "ValPrefs" are valid procedures and "GSprite_ActionData" is a valid structure, all of which are declared before the given procedure.

What am I doing wrong?

Re: Procedure giving a syntax error

Posted: Wed Jun 19, 2013 11:12 am
by eesau
You need to pass a pointer to the structure, using *GroupData.GSprite_ActionData and then reference *GroupData inside the procedure (instead of GroupData).

Re: Procedure giving a syntax error

Posted: Wed Jun 19, 2013 11:56 am
by BASICBasher
I have rewritten the code to:

Code: Select all

Procedure GSprite_ReadGroup(Name.s, *GroupData.GSprite_ActionData)
	PreferenceGroup(Name)
	If BoolPrefs("Used")
		With *GroupData
			\Frames = ValPrefs("Frames")
			*GroupData\HasDirections = BoolPrefs("HasDirections")
			If BoolPrefs("Tiled")
				*GroupData\XTile = ValPrefs("XTile")
				*GroupData\YTile = ValPrefs("YTile")
			EndIf
		EndWith
	EndIf
EndProcedure
That seems to work thank you, will being a pointer affect the code in any other way?
Could I still use a 'WITH' command if I am using a pointer?

Re: Procedure giving a syntax error

Posted: Wed Jun 19, 2013 12:02 pm
by eesau
BASICBasher wrote:That seems to work thank you, will being a pointer affect the code in any other way?
Could I still use a 'WITH' command if I am using a pointer?
Being a pointer does have its own inclinations but in this case shouldn't really complicate anything. And sure, you can still use With for additional readability.