Issue with calling global ints in repeatedly execute

Started by Hobo Joe, Sun 07/09/2008 17:02:49

Previous topic - Next topic

Hobo Joe

I'm trying to do this:

function repeatedly_execute() {
  // put anything you want to happen every game cycle here

  if (GetGlobalInt (hungry)> GetGlobalInt (pee)){
    cEgo.Walk(74, 199, eNoBlock, eWalkableAreas);
    cEgo.FaceLocation(74, 160, eNoBlock);
  }
  else if (GetGlobalInt (pee)> GetGlobalInt (hungry)){
    cEgo.Walk(301, 199, eNoBlock, eWalkableAreas);
  }
 
}

So he'll walk one way if his "hungry" int is greater than blah blah yeah you get it. The problem is, I've set up the ints and what they do in the game start section, and the repeatedly execute here gives me a script error telling me that those ints don't exist. How do I fix this?

Also, how can I make an int that counts up slowly over time?
Yay, I'm Hobo..... Joe...

Makeout Patrol

The getGlobalInt() and setGlobalInt don't support named variables; you're either going to have to use numbers and make a note somewhere what number represents what (I put it in the top of my global script in a commented out area), as follows:

function repeatedly_execute() {
  // put anything you want to happen every game cycle here

  if (GetGlobalInt (0)> GetGlobalInt (1)){
    cEgo.Walk(74, 199, eNoBlock, eWalkableAreas);
    cEgo.FaceLocation(74, 160, eNoBlock);
  }
  else if (GetGlobalInt (1)> GetGlobalInt (0)){
    cEgo.Walk(301, 199, eNoBlock, eWalkableAreas);
  }


Alternatively, you can create the named global variables. I don't recall off the top of my head how to do it in simple scripting, but it involves a bunch of exporting and importing and you can probably read about it in the manual. If you have AGS 3.1 (I think, might be another version) or later, you can simply open the 'Global Variables' window, create variables for yourself, and use their names in the script, as follows:

function repeatedly_execute() {
  // put anything you want to happen every game cycle here

  if (hungry > pee){
    cEgo.Walk(74, 199, eNoBlock, eWalkableAreas);
    cEgo.FaceLocation(74, 160, eNoBlock);
  }
  else if (pee > hungry){
    cEgo.Walk(301, 199, eNoBlock, eWalkableAreas);
  }

}

}

Khris

Hobo Joe, you really need to get the use of GlobalInts straight, if you insist on using them although you were advised against it in the other thread.

GlobalInts are like 500 boxes you can put numbers in.
SetGlobalInt(2, 34); will put 34 in box #2.
GetGlobalInt(5) equals/returns the contents (the number) stored in box #5.

So writing "SetGlobalInt(hungry, 5);" will not set a variable "hungry" to the value 5; it will put 5 in one of the 500 "boxes" depending on what "hungry" is currently set to.
If "hungry" equals 7, you will put 5 into box #7. If hungry equals -1, you will get an error during the game.

Assuming you're using the latest version of AGS, there should be an entry called "Global Variables" in the editor tree (right above "Scripts"). Double click it and then add the hungry, sad and other variables. Leave the type set to "int", enter the name and the value they're supposed to hold at the start of the game.

In the game, use code like shown in Makeout Patrol's second example.

Hobo Joe

Okay. So. I've changed the global int crap to setgraphical variable, downloaded the latest version of AGS and set up the global variables as "int" with their names and a value of 0 each. Now I get an error with this:

  SetGraphicalVariable ("thappy", Random(10));

the error is -

Error: SetGraphicalVariable: interaction variable 'thappy' not found

What did I do wrong NOW? ???
Yay, I'm Hobo..... Joe...

Dualnames

Quote from: Hobo Joe on Sun 07/09/2008 22:29:54
Okay. So. I've changed the global int crap to setgraphical variable, downloaded the latest version of AGS and set up the global variables as "int" with their names and a value of 0 each. Now I get an error with this:

  SetGraphicalVariable ("thappy", Random(10));

the error is -

Error: SetGraphicalVariable: interaction variable 'thappy' not found

What did I do wrong NOW? ???

You need to change from setgraphicavariable to global int..
So you need is this
SetGlobalInt(thappy,Random(10));
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Khris

Arrgh.

Hobo Joe:
Don't use GlobalInts. Don't use SetGraphicalVariable.
Just:
  thappy = Random(10);

Like I said, use them like Makeout Patrol said; DIRECTLY in the script.

Hobo Joe

Yeah. I figured it out by, shockingly enough, checking the help file and then paying attention. Sorry. I'm good on that now. Now I just have to figure out what ELSE I'm doing wrong.
Yay, I'm Hobo..... Joe...

SMF spam blocked by CleanTalk