Where do I change variables in rooms?

Started by Clarabella, Mon 03/11/2008 19:57:43

Previous topic - Next topic

Clarabella

Hi, I know this is an extremely stupid problem, but I can't manage to solve it.
I want Talk function with a non player character to change when he (or she) is in a different room. To do this I set a "int" variable and make it change when room changes. So, I use this code: in the globalscript.ash I declare:

int BlaBla;

Then, I put the changing of the variable inside the function room_FirstLoad, like this:

function room_FirstLoad()
{
BlaBla = 1;
}

in room 1; BlaBla = 2 in room 2 etc.

And then I use this code in the globalscript.asc

function cJames_Talk()
{
if (BlaBla == 1)
{dJames1.Start();}
if (BlaBla == 2)
{dJames2.Start();}
}

But this doesn't work!  Why? :(
When I make the player and James interact nothing happens.
Where is my mistake?

Thanks everyone for help and patience!

NOTE: I use AGS 3.0

Khris

First of all, don't put variable declarations in the header. There's tons of threads explaining the dos and donts of global variables.
Secondly, you can check the current room using player.Room:
Code: ags
function cJames_Talk() {
  if (player.Room == 1) dJames1.Start();
  if (player.Room == 2) dJames2.Start();
}

(You don't need the {} if only a single command's execution depends on an if-check.)

Clarabella

Quote from: KhrisMUC on Mon 03/11/2008 20:06:24
First of all, don't put variable declarations in the header. There's tons of threads explaining the dos and donts of global variables.

I'm sorry, I put it there because if I put it in the globalscript.asc the debugger gave me the error "undefined token" (however, you're right, I have to study better...  :P).

Quote
Secondly, you can check the current room using player.Room:
Code: ags
function cJames_Talk() {
  if (player.Room == 1) dJames1.Start();
  if (player.Room == 2) dJames2.Start();
}

(You don't need the {} if only a single command's execution depends on an if-check.)

didn't know this function, wow, great! I'll use this.
Thank you very much!

Khris

You're welcome :)

Global vars:
Code: ags
// .ash
import type name;

//.asc
type name;
export name;


Just replace "type" with int or String or whatever.

Pumaman

Also, you really don't need to do any of that import/export stuff at all, that's what the Global Variables editor is there for!!

SMF spam blocked by CleanTalk