|
Joined: Sep 2005
Posts: 14
Pikka bird
|
OP
Pikka bird
Joined: Sep 2005
Posts: 14 |
Ok, so I'm working on writing a for loop (for the second time) and I got to where everything works but the while loop part. Here's my code:
if ($+(%,$gettok(%evalwhile,1,32)) $gettok(%evalwhile,2,32) $gettok(%evalwhile,3,32)) {
echo -a got here
}
where %evalwhile = "var < 5" so basically, the if statement looks like this when it's evaluated:
if (%var < 5) {
echo -a got here
}
For some reason though, when %var is greater than 5, it returns true. I'm thinking that this is because it's treating it as a string, and is returning true every time because of the $+(%,$gettok(%evalwhile,1,32)) part. Here's the entire code of what I'm working on:
for {
if ($1 !isnum) { echo -a The first token must be "$scriptline" | halt }
if (.txt !isin $2) { echo -a The second token must have ".txt" in it | halt }
if ($gettok($3-,0,59) != 3) { echo -a There must be three statements seperated by ;'s | halt }
set %place 1
while ($gettok($3-,%place,59) != $null) {
;executes each section seperately, divided by $chr(59)
set %tok $gettok($3-,%place,59)
set %subplace 1
if (%place == 1) {
;first section. Initializes variables, in "variable = value" syntax. Each statement seperated by commas. _WORKS_
while ($gettok(%tok, %subplace, 44) != $null) {
set %subtok $remove($gettok(%tok, %subplace, 44),$chr(32))
set $+(%,$gettok(%subtok,1,61)) $gettok(%subtok,2,61) | ;sets the variable from the first statement, $chr(61) = "="
inc %subplace
}
}
else if (%place == 2) {
;sets the while loop
set %evalwhile %tok
}
else if (%place == 3) {
;anything made within the third section is done at the end. Can have more than one command with seperation of either | or ,
if ($replace($gettok($3-,%place,59),$chr(44),$chr(124)),1 != $null) {
set %exec $replace($gettok($3-,%place,59),$chr(44),$chr(124))
}
}
inc %place
}
set %forcount $1
while (for !isin $read($2,%forcount)) {
inc %forcount
}
inc %forcount
write -c for.txt 0
while (:FOREND !isin $read($2,%forcount)) {
var %line = $read($2,%forcount)
var %linecount = 1
while ($gettok(%line,%linecount,32) != $null) {
echo -a %line
if ($left($gettok(%line,%linecount,32),1) == $chr(37)) {
echo -1 %line
var %line = $replace($gettok(%line,%linecount,32), $gettok(%line,%linecount,32), $($gettok(%line,%linecount,32),1 )))
}
inc %linecount
}
write for.txt $remove(%line,$chr(59))
inc %forcount
}
echo -a %evalwhile
:while
set %forcount 1
while ($read(for.txt,%forcount) != $null) {
$read(for.txt,%forcount)
if ($gettok(%exec,2,32) isalpha) $gettok(%exec,1,32) $+(%,$gettok(%exec,2,32))
inc %forcount
}
set %evalwhile2 $+(%,$gettok(%evalwhile,1,32)) $gettok(%evalwhile,2,32) $gettok(%evalwhile,3,32)
echo -a %evalwhile2
if ($+(%,$gettok(%evalwhile,1,32)) $gettok(%evalwhile,2,32) $gettok(%evalwhile,3,32)) {
echo -a got here
if ($gettok(%evalwhile,1,32) isalpha) goto while
}
else halt
}
which can be tested with:
/testing {
for $scriptline aliases1.txt var = 3;var < 5 ;inc var {
me hi
:FOREND
}
}
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
//var %var = 10 | if (% $+ var < 5) echo yes
This will always be yes, as it's comparing the literal "%var" string to 5.
You must use eval to let the variable evaluate. Here's an example:
//var %var = 1 | while ($(% $+ var,2) < 5) inc -s %var
Evaluation brackets work as well:
//var %var = 1 | while (% [ $+ var ] < 5) inc -s %var
With an identifier instead of just a plain string "var":
//var %var = 1 | while (% [ $+ [ $gettok(var,1,32) ] ] < 5) inc -s %var
Gone.
|
|
|
|
Joined: Aug 2005
Posts: 1,052
Hoopy frood
|
Hoopy frood
Joined: Aug 2005
Posts: 1,052 |
FIberOptics by any chance did you create a public script as of yet? if so id like to see how well its constructed you seem to know alot
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
I've only released a couple of snippets on scripting sites such as www.mircscripts.org and www.mirc.net.The snippets are all involving COM though, so I don't know if you'll be able to make much of them. You can check them out here Apart from that, all my knowledge is spread accros over 1400 posts on this forum, and 300 or so on the mircscripts.org forum. I will never make a full script, because I only like coding difficult main functionality, and not all the stuff that you would find in a basic full script. That's not challenging enough, just a lot of work :tongue: Btw if you want to see a really well structured script, that also works great you should check out Peace and Protection 4.22 by pai, one of the best full scripts ever. Unfortunately it's not up to date anymore with the latest version of mIRC (I think it's only compatible with 6.01) Even though it's old, there's still a lot to learn from it. Another script that should definitely be checked out is airc by tabo. Again, an old full script, but one of the best ever. One thing that you will notice, is that the gui of those scripts is nothing compared to the scripts you see nowadays who are bulky with dll's. In other words they look old(er), though that's not so important scripting-wise. There are more full scripts worth checking out but I thought those two should definitely be mentioned.
Gone.
|
|
|
|
|