Hi,
Search isn't working right now.
I want to change a variable based on what room the player is in.
function Button5_OnClick(GUIControl *control, MouseButton button)
{
if (cEgo.Room(4)== true){
int Ascore +=1;
cEgo.ChangeRoom(2);
}
the above isn't working, because
Parse error in expr near 'cEgo'
Any suggestions?
Slightly wrong syntax, try this:
if (cEgo.Room == 4)
int Ascore += 1;
This also won't work. Or, I don't know, it might, but it doesn't make any sense. What are you trying to do here? The += operator is an incremental assignment and is equivalent to:
int Ascore = Ascore + 1;
If you're creating a new variable called Ascore then why are you trying to increment it by 1 immediately? If you just want to set it equal to 1 then use the assignment operator:
int Ascore = 1;
If you're trying to reference an existing variable, you're not, you're creating a new one. Variables can be exported from the script they are created in (only if created outside of any functions) and imported into another script or a script header (and thereby every subsequent script). Or if the variable is defined in the Global Variables pane then AGS handles that for you. So if that's what you're trying to do, then that's still not right.
This is very, very basic programming. Please check out the scripting tutorial in the manual, it should help you get a grasp on things like this.
Also, the second } is missing.
Assuming that Ascore is a global int:
function Button5_OnClick(GUIControl *control, MouseButton button)
{
if (cEgo.Room == 4) {
Ascore++; // increment by 1
cEgo.ChangeRoom(2);
}
}
Thanks all.
:-[
(Yes, the answer was in the manual.)