Help with variables in global script

Started by , Thu 17/03/2005 15:58:41

Previous topic - Next topic

Samuel

when I try to save my game it says "error in global script, (line 6): undifined symbol 'paint'."  my code is:

function dialog_request(int parameter) {

  if (parameter == 1) { // if "run-script 1" used
   if (paint == 0)  {
   MoveCharacter (TROY,246,146);
    while (character[TROY].walking) Wait(1);
     SetCharacterView(TROY,4);
      AnimateCharacter(TROY,0,0,0);
      while(character[TROY].animating) Wait(1);
      ReleaseCharacterView(TROY);
     SetCharacterView(PEASANT,2);
      AnimateCharacter(PEASANT,0,0,0);
      while(character[PEASANT].animating) Wait(1);
}
    else if (paint == 1) {
    MoveCharacter (TROY,246,146);
    while (character[TROY].walking) Wait(1);
     SetCharacterView(TROY,7);
      AnimateCharacter(TROY,0,0,0);
      while(character[TROY].animating) Wait(1);
      ReleaseCharacterView(TROY);
     SetCharacterView(PEASANT,2);
      AnimateCharacter(PEASANT,0,0,0);
      while(character[PEASANT].animating) Wait(1);   

}
if (parameter == 2) { // if "run-script 2" used
   MoveCharacter (PEASANT,500,163);
    while (character[PEASANT].walking) Wait(1);     
     NewRoomNPC(PEASANT,2,100,50); 
}

Its supposed to check a variable and if its a certain value he chages to different animations.  but it wont see the variables.  sorry if this is a noobish question.

any help is appreciated.

Ashen

Have you declared 'paint' as a global variable? I don't think dialog_request recognises room variables.
I know what you're thinking ... Don't think that.

Samuel


strazer

Where have you declared the paint variable?
To be able to access a global variable in room scripts, you have to export it from the global script and import it in the main script header or the room script. If you declare the variable in the main script header, you effectively have several seperate variables, one in the main global script and one for each room.
So do this:

Code: ags

// main global script

int paint;
export paint;


Then, if you need to access the variable in all rooms:

Code: ags

// Main script header

import int paint;


Or import it only in the rooms where you need it:

Code: ags

// room script

import int paint;

Samuel

I put the code in and it stopped giving me error messages but it still wont work.
the idea is to set the variable to 1,  and then my NPC checks the variable and depending on what number it is you can talk to him or if it is set to 1 it will display a message instead.  does it have somthing to do with my NPC?  do I have to add somthing so he'll import the variable too?

currently my code is:

// main global script
int paint;
export paint;

int dead;
export dead;

function dialog_request(int parameter) {
  if (paint == 0)
  if (parameter == 1) { // if "run-script 1" used
   MoveCharacter (TROY,246,146);
    while (character[TROY].walking) Wait(1);
     SetCharacterView(TROY,4);
      AnimateCharacter(TROY,0,0,0);
      while(character[TROY].animating) Wait(1);
      ReleaseCharacterView(TROY);
     SetCharacterView(PEASANT,2);
      AnimateCharacter(PEASANT,0,0,0);
      while(character[PEASANT].animating) Wait(1);
      dead = 1;
}
else if(paint == 1)
    {
    MoveCharacter (TROY,246,146);
    while (character[TROY].walking) Wait(1);
     SetCharacterView(TROY,7);
      AnimateCharacter(TROY,0,0,0);
      while(character[TROY].animating) Wait(1);
      ReleaseCharacterView(TROY);
     SetCharacterView(PEASANT,2);
      AnimateCharacter(PEASANT,0,0,0);
      while(character[PEASANT].animating) Wait(1);   

}
else if (parameter == 2) { // if "run-script 2" used
   MoveCharacter (PEASANT,500,163);
    while (character[PEASANT].walking) Wait(1);     
     NewRoomNPC(PEASANT,2,100,50); 
}
}

oh, and there are two variables.  one for my player character and one for the NPC.  neither are working.  what am I doing wrong?

strazer

#5
Quotedo I have to add somthing so he'll import the variable too?

Depends on where the variable is set. Character interactions are handled in the global script, so if you set it there, you don't even need to export it.
If you want to set it within the interaction of an object or hotspot, you need to export it from the global script and import it in the room script as I have shown above.

As for the dialog_request function, do you want this?:

Code: ags

function dialog_request(int parameter) {

  if (parameter == 1) { // if "run-script 1" used

    if (paint == 0) {
      MoveCharacter (TROY,246,146);
      while (character[TROY].walking) Wait(1);
      SetCharacterView(TROY,4);
      AnimateCharacter(TROY,0,0,0);
      while(character[TROY].animating) Wait(1);
      ReleaseCharacterView(TROY);
      SetCharacterView(PEASANT,2);
      AnimateCharacter(PEASANT,0,0,0);
      while(character[PEASANT].animating) Wait(1);
      dead = 1;
    }
    else if (paint == 1) {
      MoveCharacter (TROY,246,146);
      while (character[TROY].walking) Wait(1);
      SetCharacterView(TROY,7);
      AnimateCharacter(TROY,0,0,0);
      while(character[TROY].animating) Wait(1);
      ReleaseCharacterView(TROY);
      SetCharacterView(PEASANT,2);
      AnimateCharacter(PEASANT,0,0,0);
      while(character[PEASANT].animating) Wait(1);   
    }

  }
  else if (parameter == 2) { // if "run-script 2" used

    MoveCharacter (PEASANT,500,163);
    while (character[PEASANT].walking) Wait(1);     
    NewRoomNPC(PEASANT,2,100,50); 

  }

}

SMF spam blocked by CleanTalk