Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: madradubhcroga on Tue 22/05/2012 16:06:11

Title: Checking what room the player is in
Post by: madradubhcroga on Tue 22/05/2012 16:06:11
Hi,

Search isn't working right now.

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

Code (AGS) Select

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?
 
Title: Re: Checking what room the player is in
Post by: on Tue 22/05/2012 16:40:07
Slightly wrong syntax, try this:

if (cEgo.Room == 4)


Title: Re: Checking what room the player is in
Post by: monkey0506 on Tue 22/05/2012 17:07:47
Code (ags) Select
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) Select
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) Select
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.
Title: Re: Checking what room the player is in
Post by: Khris on Tue 22/05/2012 17:11:13
Also, the second } is missing.
Assuming that Ascore is a global int:
Code (ags) Select
function Button5_OnClick(GUIControl *control, MouseButton button)
{
  if (cEgo.Room == 4) {
    Ascore++;   // increment by 1
    cEgo.ChangeRoom(2);
  }
}
Title: Re: Checking what room the player is in
Post by: madradubhcroga on Tue 22/05/2012 17:51:11
Thanks all.

:-[

(Yes, the answer was in the manual.)