Checking what room the player is in

Started by madradubhcroga, Tue 22/05/2012 16:06:11

Previous topic - Next topic

madradubhcroga

Hi,

Search isn't working right now.

I want to change a variable based on what room the player is in.

Code: AGS

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?
 

Ghost

Slightly wrong syntax, try this:

if (cEgo.Room == 4)



monkey0506

Code: ags
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:

Code: ags
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:

Code: ags
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.

Khris

Also, the second } is missing.
Assuming that Ascore is a global int:
Code: ags
function Button5_OnClick(GUIControl *control, MouseButton button)
{
  if (cEgo.Room == 4) {
    Ascore++;   // increment by 1
    cEgo.ChangeRoom(2);
  }
}

madradubhcroga

Thanks all.

:-[

(Yes, the answer was in the manual.)

SMF spam blocked by CleanTalk