Script problem with globalInt

Started by , Mon 12/02/2007 13:59:03

Previous topic - Next topic

Emilio


  I need to use globalInt variables but the tutorial description inst enought clear. my question is the following,

          1.- Where and how i declare a globalint variable (for example in the global script
                                                                                                                                           globalInt a;)

          2.- How to use GetGlobalInt and SetGlobalInt. For example when Roger does repeatdly something action over a hotspot my globalInt should increase an unity and so in a diferent room when my the globalInt variable has reach certain value Robert could talk with a key person ...... or similar.


   I'll be very grateful if someone help me, so my game is near the end, thanks
         

Ashen

#1
Read the BFAQ

1.
You don't declare GlobalInts in that way, they just exist. You can, however, declare an int and import/export it (explained in more detail in that BFAQ link) to make it Global. (Often prefered to using GlobalInts, as they can have descriptive names and are - IMO - easier to deal with.)

2.
You don't use Get/SetGlobalInt to manipulate those ints. If you still want to know about using Get/SetGlobalInt, that's in the BFAQ, too. If not, use the operators as described in the manual. There's a couple of others you might find useful, e.g.:
Code: ags

myvar += 3; // is equivilant to 'myvar = myvar + 3'
myvar -= 5; // is equivilant to 'myvar = myvar - 5'

myvar ++;
myvar --; // 'myvar += 1' and 'myvar -= 1' respectively


Between the BFAQ, the manual and just browsing previous threads, you should be able to work out anything else you need.
I know what you're thinking ... Don't think that.

AdamM

I'm having trouble understanding these as well. Set/GetGlobalInt seem to work fine, but the manual implies that export/importing ints means you can only take ints from global to room scripts; not the other way around?

Ashen

That's right. If you want a variable to be used across a number of rooms, it has to be declared in (and exported from) the Global script or a module - you can't export ints from Room scripts. (You can import them on a room-by-room basis, if you need to - but using the Global Header is best if you're likely to need it in all/most rooms.)
I know what you're thinking ... Don't think that.

Da_Elf

jus tcurious what the pros/cons are in the use of graphical variables and global variables?

Ashen

As I see it the pros/cons are:

Graphical Variables:
CONS:
  Limited (100 Global Graphical, Not sure about Room-specific ones).
  Clunky to use (Have to be created via Interaction Editor, Get/SetGraphicVariable("my variable" ... a hassle to type, IMO).
  Two words: 'Interaction Editor'. (Not the most objective point, but I can't stand the Interaction Editor. It's ugly, awkward to use and limiting.)
PROS:
  Don't have to import/export them.
  Named, so it's easier to tell what they do (unlike GlobalInts)

GlobalInts:
CONS:
  Limited (500)
  While not quite as clunky to use as Graphical Variables, still not as easy as custom ints.
  Not named, so it's not always obvious what, for example, GetGlobalInt(27) is actually checking.
PROS:
  Don't have to import/export them.
  Aren't in any way connected to the Interaction Editor.

Custom Ints:
CONS:
  Have to be imported/exported. (Not actually as big a problem as people seem to think it'll be...)
PROS:
  Unlimited.
  Easy to use (if (myVar == 2) and myVar = 3, etc, instead of the Get/Set functions).
  Named.
  Aren't in any way connected to the Interaction Editor. :)
  If you don't need them to be Global, much easier to create as you go than Graphical Variables (and of course there's no equivalent RoomInt[i/] array).
 
Similar arguments stand for Global/Room Messages vs GlobalStrings vs custom Strings. (Except you can't alter Global/Room messages.)
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk