mIRC Home    About    Download    Register    News    Help

Print Thread
Updating Mass amounts of Variables #1255 12/12/02 03:42 AM
Joined: Dec 2002
Posts: 2
D
Druke Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
D
Joined: Dec 2002
Posts: 2
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?

Re: Updating Mass amounts of Variables #1256 12/12/02 04:01 AM
Joined: Dec 2002
Posts: 144
D
Dana Offline
Vogon poet
Offline
Vogon poet
D
Joined: Dec 2002
Posts: 144
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.*


"Any sufficiently advanced technology is indistinguishable from magic." - Arthur C. Clarke
Re: Updating Mass amounts of Variables #1257 12/12/02 06:08 AM
Joined: Dec 2002
Posts: 580
N
NaquadaServ Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 580
No idea [censored] you are doing with that code!

Look in the help for hash tables....

NaquadaServ

Last edited by Merlin; 12/12/02 06:39 AM.

NaquadaBomb
www.mirc-dll.com
Re: Updating Mass amounts of Variables #1258 12/12/02 06:58 AM
Joined: Dec 2002
Posts: 164
M
Merlin Offline
Vogon poet
Offline
Vogon poet
M
Joined: Dec 2002
Posts: 164
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.


DALnet: #HelpDesk, #mIRC, #MISHScript - Undernet: #mIRC, #mIRC-Scripts
Re: Updating Mass amounts of Variables #1259 12/12/02 05:48 PM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
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.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Re: Updating Mass amounts of Variables #1260 13/12/02 04:17 AM
Joined: Dec 2002
Posts: 2
D
Druke Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
D
Joined: Dec 2002
Posts: 2
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.

Re: Updating Mass amounts of Variables #1261 13/12/02 04:26 AM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
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.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C