mIRC Home    About    Download    Register    News    Help

Print Thread
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?

Joined: Dec 2002
Posts: 144
D
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
Joined: Dec 2002
Posts: 580
N
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
Joined: Dec 2002
Posts: 164
M
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
Joined: Dec 2002
Posts: 1,321
H
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
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.

Joined: Dec 2002
Posts: 1,321
H
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

Link Copied to Clipboard