I have used rpgmaker, For me it as a good lesson! But i always did not know what a variable was!
I know you had them in Rpgmaker but also in this software! I hear from people it is hard too discribe what a variable is! I know a variable is something important while building a game.
I just cannot find the anser about this! I hope somebody could tell me more about variables and events,, But a event is thesame as an interaction right?
But hopefully someone can explain me how a Variable works,, when you need it etc.
Thanks again!
I'll start with explaining an event:
Go to any Object, Hotspot, Character, Region or a Room itself and click its "Interaction..." button. This will open a window listing the possible events for that thing.
Example: say there's a ball object in your first room and you click on it using the look cursor. This will trigger the "Look at object" event in the ball's interaction window.
Or say the player ends up in another room: the first thing AGS will do after loading the new room is trigger the "player enters screen (before fadein)" event of that room. After that, it'll fade in, then trigger the "player enters screen (after fadein)" event, and so on.
----
Variables are a bit harder to explain. It's very easy though once you got the concept.
Think of variables as labeled boxes you can put stuff in.
int a=0;
This will create a new box, label it "a" and put a "0" (zero) inside. That contents of the box is called the variable's value. Int is short for integer, meaning a whole(?) number.
int b=0;
b=a+2;
This will create another box labeled "b".
Then the number inside box a is taken, 2 is added to it, the result is then put in box b.
There are other types of variables, the important ones being float and String.
float variables contain numbers like 3.657, Strings contain pieces of text like "AGS".
The main purpose of variables is to store values needed for later use.
Say your game character learns a certain ability at some point in the game. You'll want to use a variable to store whether he has already learned it or has yet to acquire the ability.
In the actual code, you'd use something like this:
int player_is_strong=0; // declare (create) variable and set it to 0
The player is going to find a tonic and as soon as he drinks it:
player_is_strong=1; // change variable's value to 1
Somewhere else in the game there's a heavy rock. If the player tries to lift it:
if (player_is_strong==1) { // for comparisons, == is used
player.Say("Yay, I've lifted the rock!");
}
If he didn't drink the tonic, the variable's value would still equal 0 at this point.
But if he did, the value of player_is_strong would be 1 now, so he'd say the sentence in the code.
This is probably by far the principal use of variables with AGS: to store the state of something, be it whether a door is locked or not, how many gold coins the player has in his possession, or if he has killed the troll or not.
Variables are absolutely essential to coding, so don't be afraid to ask about anything else that's unclear to you.
That sounds intresting,, so a variable is an interaction that only can be turned on when you accomplish something that turns it on! The variable can also be used for ingame money right?
But only one thing!
I try too expplain my big big problem at the moment!
Where do i have too place the codes?
Not only those variable codes but also other commands.
Because you can find codes for almost every action you want on this forum. but where do you place them?
But i tell the truth. i have not yet read the scripting tutorials in the help topics, but i''d like it if someone can still tell me something about placing script codes. I hope not too complicated but however, allready thanks for the ansers!
;D ;D
No, a variable isn't an interaction. A variable is a variable.
It isn't turned on, it is either set to a value or the value is read back.
That is done in interactions, or more precisely, in the function representing the interaction.
The term "interaction editor" is a bit misleading, it should be called "event editor".
About placing code:
Please look it up in the Beginner's FAQ, I think Ashen linked you to it in your other thread.
Just to try and clarify what Khris has said:
Events
An event isn't actually an interaction itself (per se) but rather the things that take place in the game that generate interactions. For example, if you tell the player character to talk to another character (say, Frank), that would generate an event similar to "Player talks to Frank".
The interaction would then be whatever you tell the engine to happen when the player talks to Frank. The most likely/most common interaction would be to run a dialog between the characters. However, you may just want to have Frank say something such as "I don't want to talk to you."
See Also: Reference (http://americangirlscouts.org/agswiki/Reference_%28manual%29#Interaction_events), Scripting event reference (http://americangirlscouts.org/agswiki/Scripting_event_reference)
Variables
A variable is a way of storing/representing data in your game. So let's say you're using the number 5 in your game a lot. Perhaps it's the maximum value for something you're scripting:
if (something > 5) {
// error!
}
But then let's say you want to raise that maximum value to say, 7. You would have to go through all your scripts changing the 5s to 7s. If you use a variable to represent the maximum value, you could do something like this:
int max = 5;
// ...
if (something > max) {
// error!
}
Then to raise the maximum value all you would need to do is change:
int max = 5;
To:
int max = 7;
As Khris has already stated, there are 3 main variable types used by AGS: int, float, and String.
int is used to represent whole integer values. You cannot store any fractional part of a number in an int, but you can store the whole part of any real number (positive or negative).
float is used to represent what are known as floating-point decimals. You can use a float to store fractional parts of numbers, usually up to about 6 decimal places (although floating-point math isn't always 100% accurate).
String is used to represent string-literals. A string-literal is a way of representing text within your script. This is done by including quotation marks around the text, such as, "This is some text." This distinguishes the text from the rest of your script so the engine knows what it is.
Just FYI, I'm using the term operators in the following examples. These are simply the symbols you can use to modify/compare the value of variables.
We've already seen some examples of how to define and set the value of ints, but I'll give another example now:
int one; // this currently holds the value 0
int two = 2; // this holds the value 2
one = 1; // use the = operator to set the value, this now holds the value 1
if (one == two) { // use the == operator to check if two ints are the same (hold the same value)
Display("They are the same!");
}
if (one != two) { // use the != operator to check if two ints are not the same
Display("They are not the same!");
}
one++; // use the ++ operator to increase an int by 1, this now holds the value 2
two--; // use the -- operator to decrease an int by 1, this now holds the value 1
two += 1; // use the += operator to increase an int by X (where X is the right-hand side of the equation, in this case 1), this now holds the value 2
one -= 1; // use the -= operator to decrease an int by X, this now holds the value 1
one += (one + two); // another example of the += operator, this now holds the value 4 (increased by the value of one (1) plus two (2) (giving us 3, plus the current value of one (1), making 4)
// other operators:
// > checks if the left side is greater than the right side
// < checks if the left side is less than the right side
// >= checks if the left side is greater than or equal to the right side
// <= checks if the left side is less than or equal to the right side
floats are used similarly to ints:
float a; // holds the value 0.0
float b = 5.0; // holds the value 5.0
a += b; // a holds the value 5.0
if (a == 5.0) { // in this case this should probably work, but it may not always work as expected
// blah
}
// instead try this:
if ((a > 4.9) && (a < 5.1)) {
// blah
}
// the other operators are the same as for ints
Strings work a bit differently, but some of the operators are the same:
String txt; // this will actually hold a special keyword called null; operating on null Strings is an illegal operation and will crash your game, always check that the String is non-null before you try to do anything with it other than setting/checking its value
if (txt == null) Display("txt is null!");
txt = "This is some text"; // this will hold the value of "This is some text"
if (txt != null) Display("txt is non-null!");
// the following operators do not work with Strings +, -, ++, --, +=, -=, >, <, >=, <=
See Also: Scripting tutorial part 1 (Variables) (http://americangirlscouts.org/agswiki/Scripting_tutorial_part_1#Variables), AGS Pointers for Dummies (Variables) (http://americangirlscouts.org/agswiki/AGS_Pointers_for_Dummies#Variables), String functions (http://americangirlscouts.org/agswiki/String_functions)
Hopefully this has helped clarify things and not just muddled you further...but in any case, reading through the scripting tutorial is definitely a good place to get started.