Re: [DG Scripts] Usage on Globals

From: Ron Hensley (ronh@SHORE.INTERCOM.NET)
Date: 08/11/98

I just want to check my undertanding of Global variables proper usage.
Example, mob that counts how many times someones entered its room. Was
trying to figure out the proper way to initialize the global to a default
value the fist time its called, and use that value in following incantations
of it. Heres a short example, that does work

   if (%startflag% == 0)
     say first time im called
     eval startflag 1
     global startflag
     say Startflag is now %startflag%
     eval startflag %startflag% + 1
     global startflag
     say ive been called before, startflag = %startflag%

My questions revolve around the proper order to put the eval statements and
the global statements. The way I did it above, was the only way I could seem
to not accidentally destroy the previous value each time, or reset it to 0,
by having a
  global myvar
as the first statement. If you do this, that var seems to be reset to 0 each
time through. Example

global startflag
eval startflag %startflag% + 1
say I have been called %startflag% times

This does: I have been called 1 times
every single time its called.Stealing from C syntax, id expected global to
work more like a static flag, ala

  global startflag 0
  eval startflag %startflag% + 1
  say %startflag%

Id expect this to set startflag to 0 this first time, but upon 2nd time
through, never touch that global, as its already been added to the var list,
thus skip it, leaving startflag at whatever value it currently has.

Well don;t know if anyone follows my train of thought or not, but curious
what other people have found when using globals.

Ron Hensley

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

This archive was generated by hypermail 2b30 : 12/15/00 PST