mIRC Homepage
Posted By: Druke Updating Mass amounts of Variables - 12/12/02 03:42 AM
I have a script that has a massive amount of variables (both local and global) that are constantly changing and must be constantly updated. However, I need some efficient way to update all the variables at once. So I decided to use a alias:

/variables {
var %num = %c
}
/counting {
set %c 1.009
var %num = %c
%c = 2
variables
echo -a %num
}

But this doesn't work, and %num remains at 1.009. So, if aliases do not pass on local variables (which is the majority of my variables), then is there a way to fix this? Or is there another way?
Posted By: Dana Re: Updating Mass amounts of Variables - 12/12/02 04:01 AM
Why don't you use global variables? But instead of using common names such as %num or %c, try things that are more script-snippet specific. You can unset the variables you don't need at the end, especially if they have a common denominator. E.g.: /unset %whatever.*
Posted By: NaquadaServ Re: Updating Mass amounts of Variables - 12/12/02 06:08 AM
No idea [censored] you are doing with that code!

Look in the help for hash tables....

NaquadaServ
Posted By: Merlin Re: Updating Mass amounts of Variables - 12/12/02 06:58 AM
An easy way to avoid variables like for 0/1 or ON/OFF is the usage of groups. For instance if you want to set a %Status to be 0 or 1 and start with a default of 0
Code:
  
#status off
 
#status end

Note the empty line between off and end. To check wether the status is on you can use this
Code:
  
  IF ($group(#status).status == on) { echo -a Status is ON } 
  ELSE { echo -a Status is OFF }

There could be any commands you would like to perform in place of those echo lines.
Another example: To toggle the status setting do this:
Code:
  
  $iif($group(#status).status == on,.disable #status,.enable #status) 

For more information please read /help $groups and /help Creating Groups.
Posted By: Hammer Re: Updating Mass amounts of Variables - 12/12/02 05:48 PM
You are confusing local variables (set with var) and global variables (set with set). When you var a local variable %var, it is only available inside the alias/popup/event script in which it was created. When you set a global variable %set, it is available (viewable or changable) by any script that is looking for it. It is one of the main ways scripters pass information between events since the variable is not destroyed when the script ends.
Code:

/counting {
  set %c 1.009
  var %num = %c
  %c = 2
  variables
  echo -a %num
}
When /counting runs, it sets up a global variable %c and sets it equal to 1.009. Next, the local variable %num is created and set equal to %c; both variables now equal 1.009. Next, %c is changed to equal 2. /variables is called to do it's job.
Code:
/variables {
  var %num = %c
}
The /variables alias will accomplish exactly nothing whatsoever. It will just create a local variable %num, set its value to whatever is current stored in the global variable %c (2), and that's it. It doesn't do anything with %num, and %num is destroyed as soon as /variables ends. Note that /variables does not know anything about the %num that was set up in /counting. /variables only knows about its own %num, though it can see %c because %c used set, not var.

Control is returned to /counting with its %c (2) and %num (1.009) unchanged by anything done by /variables. Therefore, when /counting echoes out the current value of %num, it will echo out 1.009.

When /counting itself completes, %num will be destroyed and %c will retain its value of 2 until another script changes its value or unsets it.
Posted By: Druke Re: Updating Mass amounts of Variables - 13/12/02 04:17 AM
When I mean a mass amounts of variables, I'm talking about 40 local variables * number of people using the bot. I'm probably going to end up using hash tables anyways.

I made a horrible example, which is cause of this confusion. But Hammer seems to know what I mean. I was hoping that there is some way to keep the local variables from terminating after the alias is complete.
Posted By: Hammer Re: Updating Mass amounts of Variables - 13/12/02 04:26 AM
Then hash tables are DEFINITELY the way to go. I think I'd use /hadd tablename $+($nick,VarName) value to add the values and $hget(tablename,$+($nick,VarName)) to retrieve the data stored in it.
© mIRC Discussion Forums