mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2012
Posts: 1
T
Mostly harmless
OP Offline
Mostly harmless
T
Joined: Dec 2012
Posts: 1
So, I'm working my search-fu and I find plenty of handy reference material (including mIRC's extensive helpfile system) and all of it seems to indicate that when assigning a variable the default value will be assumed to be numerical? My assumption is based off of a parameter to set plain-text but none to set value. Well, I need it to accept a numerical input so that I can use it for equations. I've tried everything I can think of to get this basic input/output to work... but, nothing seems to be working. What am I doing wrong? Yes, I am prepared to facepalm; but, I'm hoping it is some setting I am ignorant of that I can toggle off and not feel dumb. wink Thanks!

ex.

Code:
/test.tertiary  {
  set %value.test = 5
    ;Set variable (value.test) to the number five.
  echo %value.test
    ;Display variable (value.test).
      ;Output:  '= 5'
      ;Desired Output:  '5'
  set %value.test = %value.test + 1
    ;Increase the value of variable (value.test) by one.
      ;I know there is a command for this, but for testing purposes the equation is more important than efficiency.
  echo %value.test
    ;Display variable (value.test).
      ;Output: '= %number + 1'
      ;Desired Output:  '6'
}

Joined: Nov 2009
Posts: 295
P
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
Well first off I see you are using = with the /set command. You don't use = with /set. Also you can't do math using /set. You can do two things really.

Use /var
which fits the syntax you are using
Code:
test.tertiary  {
  var %value.test = 5
  ;Set variable (value.test) to the number five.
  echo -a %value.test
  ;Display variable (value.test).
  ;Output:  '= 5'
  ;Desired Output:  '5'
  var %value.test = %value.test + 1
  ;Increase the value of variable (value.test) by one.
  ;I know there is a command for this, but for testing purposes the equation is more important than efficiency.
  echo -a %value.test
  ;Display variable (value.test).
  ;Output: '= %number + 1'
  ;Desired Output:  '6'
}



Or /set
which requires the use of $calc for the second part
Code:
test.tertiary  {
  set %value.test 5
  ;Set variable (value.test) to the number five.
  echo -a %value.test
  ;Display variable (value.test).
  ;Output:  '= 5'
  ;Desired Output:  '5'
  set %value.test $calc( %value.test + 1 )
  ;Increase the value of variable (value.test) by one.
  ;I know there is a command for this, but for testing purposes the equation is more important than efficiency.
  echo -a %value.test
  ;Display variable (value.test).
  ;Output: '= %number + 1'
  ;Desired Output:  '6'
}


I personally prefer /set but many people seem to loathe it. Oh and if anyone says it's an documented feature, it isn't any more. No clue when it made it in the help file, but that was an argument against it for a long time.

So really it's up to you which you'd like to use.

Also about variables being numeric or text, I don't believe mirc variables have a type unlike other languages. If you end up passing text to the /inc command for instance it just does nothing. So it's just up the user to keep track of which variables are what type or add checks if needed.


http://scripting.pball.win
My personal site with some scripts I've released.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I don't know anyone who would say /set is undocumented. /set has probably been around as long as /var. The reason people will suggest /var instead of /set is because /var is temporary (loaded in memory), while /set is remains until you /unset it (written to disk). If you are doing something that doesn't need to be stored, then /var makes more sense. If you are doing something that does need stored for a later use, then /set is needed. For this example script, the values aren't needed once the script completes, so /var is better. Otherwise, you have to manually /unset the variable when you finish. And although speed isn't going to be noticeably different unless you have a ton of /set or /var in a script, it's still faster to put data in memory than to write to disk and then delete it from disk when done.

Anyhow, to the OP... as was mentioned, /var uses =, but /set does not. Examples:

/var %test = 5
/set %test 5

Both do the same thing, but /var only sets the variable until the end of the current event/alias and then it's removed. Note that with /var, you can use basic math:

/var %test = %test + 1

You cannot do that with /set. In addition, if you are just adding or subtracting, the use of /inc or /dec works well.

/inc %test (increases the value by 1)
/inc %test 5 (increases the value by 5)
/dec %test (decreases the value by 1)
/dec %test 5 (decreases the value by 5)

As far as making sure that the value is a number, variables don't have types as was mentioned. mIRC will just either ignore what you try doing or throw an error if you try manipulating a variable that has the wrong type of data in it. So you would need to test the variable if you think it may not be a number. A simple test is:

if (%variable isnum) { do something }

or

if (%variable !isnum) { do something }

The ! means "not".


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
You can do basic math operation with /set too.
And all variables are in memory, everything is pretty much in memory until they are written to disk in mIRC, global variables are in vars.ini (or the file assigned for global variables) but that file, just like any .ini files mirc uses, is in memory too.
The local/global difference isn't related to the memory/disk difference

Last edited by Wims; 17/12/12 12:12 AM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ok. I see that variables aren't written immediately. My mistake. I knew it was in memory, but I thought it was still written. And it looks like I was wrong with basic math. I could have sworn I'd tried that years ago, so perhaps that has changed since I tried it. Either way, /var makes more sense for a variable that does not need to be stored.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
I'm didn't check but it's almost certain that basic operations were added at the same time for /var and /set, but yeah, I wasn't suggesting using /set.
As for the .ini files, they are eventually written to the disk from time to time, perhaps there's a timer for that in mIRC, you can also force the save with /saveini.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard