Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: spaceoddity on Fri 28/05/2010 20:25:25

Title: I don't get Get
Post by: spaceoddity on Fri 28/05/2010 20:25:25
From watching Densming's videos and reading his spectacular new book, I feel like I've learned a great deal about scripting in AGS. However, I keep stumbling over scripting commands with "Get" in them. I don't get Get. I don't understand why it's used, and why it's needed. Example:


if (GetGameSpeed() > 40) {
  SetGameSpeed(40);
}


it seems like you could just write:


if (GameSpeed)>40){
  SetGameSpeed(40);
}


I know you can't actually do that. But why do you need Get for certain things, and you don't need them for others? Why does GameSpeed need to be "Gotten", yet things like Player.PreviousRoom don't need to be "Gotten"?

Why do we have to Get things? Aren't they already there?
Title: Re: I don't get Get
Post by: discordance on Fri 28/05/2010 20:43:45
If I'm right GetGameSpeed() is just a function that returns the value of a game speed variable. Why you can't just directly access that variable, I'm not sure. It's probably just a holdover from less object-oriented versions of AGS.
Title: Re: I don't get Get
Post by: barefoot on Sat 29/05/2010 09:31:34
It's a Built-in Hardcoded piece of script... like in other languages like c and java...

Hazard a guess:
GET- ie retrieve that function, in this case GetSetSpeed, and change its variable from default to your own variable ie 40.

I think it returns a variable which you set yourself for the getgamespeed script ie speed=40 etc  (but don't quote me on this)..

But if it works then why bother to wonder why.... curiosity I suppose....

I no doubt expect many language experts on here could explain the full thing...and shoot me down...;)


barefoot
Title: Re: I don't get Get
Post by: Khris on Sat 29/05/2010 12:06:02
Very often, objects contain properties that can't be changed directly due to the property being private. This is not done arbitrarily but usually to ensure that the variable isn't changed to something that crashes the game.
So instead of making the property itself public, the object provides public SetX and GetX functions to change/retrieve the value; Set making sure that the value isn't changed to nonsense.

Then there's the issue whether the object is static or not; a static object exists only once, while a non-static object usually has multiple instances.

E.g. there's Game.GetLocationName(int x, int y), a static String, and GetLocationType(int x, int y), a non-static int. The former is static because it reads the string off a static list of strings, this list also being a member of the static Game object, while the latter isn't static because it doesn't have to be.

It comes down to conventions and rules of the programming language that's used.
Title: Re: I don't get Get
Post by: barefoot on Sat 29/05/2010 12:19:47
Nicely put Khris..


barefoot