Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: kantor_98 on Mon 13/11/2006 08:37:34

Title: user-defined variables
Post by: kantor_98 on Mon 13/11/2006 08:37:34
1.Do anybody knows if there is possible to have user-defined general variables ?
2. if I use a local variable, where must I define her ? In HELPO I see that it is to be defined in a specific room. But then it comes the next problem - see question 3.
3. Local variable: if I give a value to the local variable in the game and I get out of the room, when I return to the room, will I find the value that I expect to my variable or must I use a Global Variable ? I mean, I I have define a variable in the strat of the room, when I re-enter the room the variable will be reset. Or not ? What if I initialise the varible  (int my_counter = 4).
4. The SAVE command save also the values for local variables ?
Thank you all
Title: Re: user-defined variables
Post by: SSH on Mon 13/11/2006 08:51:13
Quote from: kantor_98 on Mon 13/11/2006 08:37:34
1.Do anybody knows if there is possible to have user-defined general variables ?
Yes, of course. Look it up in the BFAQ or manual.

Quote
2. if I use a local variable, where must I define her ? In HELPO I see that it is to be defined in a specific room. But then it comes the next problem - see question 3.
You can have variables local to a function or local to a room. I assume you mean the latter.


Quote
3. Local variable: if I give a value to the local variable in the game and I get out of the room, when I return to the room, will I find the value that I expect to my variable or must I use a Global Variable ? I mean, I I have define a variable in the strat of the room, when I re-enter the room the variable will be reset. Or not ? What if I initialise the varible  (int my_counter = 4).

The room state is saved for the first 300 rooms.

Quote
4. The SAVE command save also the values for local variables ?
Quote
Yes

Title: Re: user-defined variables
Post by: Gilbert on Mon 13/11/2006 08:53:02
1. Can you elaborate on the question? Since i don't know what you really meant by user-defined "general" variables. Nearly everything that takes value could be defined by a user according to his needs, like the integer, string, etc. variabls used in scripting (and even arrays/structs of them), properties, etc.
2. Depends on what you meant by "local", I'll assume you're talking about text script variables here, it could be a) local to a script (be it the global script or a specific room script) or b) local to a function.
Ã, a) If it's local to a script, just define it on top of the script (outside of any function), eg.:
Ã,  Ã,  Ã, int blah;
Ã,  Ã,  Ã, Note that variables defined this way in the global script are by default local to the global script only, if you want them to be accessible by other rooms' scripts you need to export them and then import them in the room scripts that need to use it.
Ã, b) If it's local to a function, just define it within the function's content, these variables will be automatically destroyed when the function ends executing.
3. Values of variables remain unchanged when you change rooms if they're defined outside of functions (see 2(a)), if they're defined within a function (see 2(b)) they'll be destroyed whenever the function ends.
4. Yes, unless they're variables only local to functions.

You may however, check out the tutorial section of the manual first, which might contain much more information for such basic problems.


P.S. SSH replied while I was typing, I'll just post anyway.
Title: Re: user-defined variables
Post by: kantor_98 on Mon 13/11/2006 09:26:39
Details: I reffer in fact to 2 ypes of varibles:
1) A variable define by me, but that I want to use all over the game, in all rooms;
2) A variable defined by me, that I will not use in other room, but when I return to the specific room in which it was created, I want to fond the value that was in it when I leaved the room

PS: how can I do "you need to export them and then import them in the room scripts that need to use it." ?
Thanks
Title: Re: user-defined variables
Post by: SSH on Mon 13/11/2006 09:38:30
http://americangirlscouts.org/agswiki/Scripting%2C_Code_%26_Interaction#Working_with_variables:_the_basics
Title: Re: user-defined variables
Post by: Ashen on Mon 13/11/2006 12:13:37
Also in the manual: export (http://www.adventuregamestudio.co.uk/manual/exportkeyword.htm) and import (http://www.adventuregamestudio.co.uk/manual/importkeyword.htm).

Please, read the Manual and the BFAQ. (Are you noticing a theme developing here?  ;))