Procedure giving a syntax error

Just starting out? Need help? Post your questions and find answers here.
BASICBasher
User
User
Posts: 26
Joined: Mon Feb 18, 2013 10:33 am

Procedure giving a syntax error

Post 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?
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Re: Procedure giving a syntax error

Post 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).
BASICBasher
User
User
Posts: 26
Joined: Mon Feb 18, 2013 10:33 am

Re: Procedure giving a syntax error

Post 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?
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Re: Procedure giving a syntax error

Post 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.
Post Reply