mIRC Home    About    Download    Register    News    Help

Print Thread
#129394 06/09/05 01:27 AM
Joined: Sep 2005
Posts: 14
C
Chappy Offline OP
Pikka bird
OP Offline
Pikka bird
C
Joined: Sep 2005
Posts: 14
Code:
for {
  if ($1 isnum) {
    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" format. Each statement seperated by commas.
        while ($gettok(%tok, %subplace, 44) != $null) {
          set %subtok $gettok(%tok, %subplace, 44)
          echo -a $gettok(%subtok,1,61) | ;shows that the first token exists
          echo -a $gettok(%subtok,2,61) | ;shows that the second token exists
          set % [ $+ [ $gettok(%subtok,1,61) ] ] $gettok(%subtok,2,61)
          inc %subplace
        }
      }
      inc %place
    }
  }
}
 


For some reason, the line:
set % [ $+ [ $gettok(%subtok,1,61) ] ] $gettok(%subtok,2,61)
isnt setting the tokens that it should be. The echos tell me the correct tokens, but the set isnt doing it. The for loop is in the following format:

/for 1 arb var = 1
where 1 is an arbitrary number (atm) and so is arb. Thanks in advance.

#129395 06/09/05 01:39 AM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
could you give an example of the input you want it to handle

#129396 06/09/05 01:42 AM
Joined: Sep 2005
Posts: 14
C
Chappy Offline OP
Pikka bird
OP Offline
Pikka bird
C
Joined: Sep 2005
Posts: 14
/for 1 arb var = 1

would return:

var
1
* /set: invalid parameters (line 516, aliases.ini)

#129397 06/09/05 02:02 AM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
Code:

/for {
  if ($1 isnum) {
    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" format. Each statement seperated by commas.
        while ($gettok(%tok, %subplace, 44) != $null) {
          set %subtok $gettok(%tok, %subplace, 44)
          echo -a $gettok(%subtok,1,61) | ;shows that the first token exists
          echo -a $gettok(%subtok,2,61) | ;shows that the second token exists
          set $+(%,$gettok(%subtok,1,61)) $gettok(%subtok,2,61)
          echo -a $eval($+(%,$gettok(%subtok,1,61)),2)
          inc %subplace
        }
      }
      inc %place
    }
  }
}

#129398 06/09/05 02:32 AM
Joined: Sep 2005
Posts: 14
C
Chappy Offline OP
Pikka bird
OP Offline
Pikka bird
C
Joined: Sep 2005
Posts: 14
Thanks for the help.

Another question: Is there a way to read things betwen "{ }"'s? The only way I can think of doing this is to write everything within the "{ }"'s into a text file and use a while loop to loop everything within that text file. It's slow, but I couln't figure out another way to do it.

example:
Code:
 
for blah blah {
  do this
  do that
  and this too
  cant forget this
}
 

Last edited by Chappy; 06/09/05 02:35 AM.
#129399 06/09/05 02:45 AM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
if I understand you correctly, yes. Using tokens as you did in the scripting above. You can also perform various tasks by setting up your script and input format to do different things based on different conditions you specify.

#129400 06/09/05 02:51 AM
Joined: Sep 2005
Posts: 14
C
Chappy Offline OP
Pikka bird
OP Offline
Pikka bird
C
Joined: Sep 2005
Posts: 14
Quote:
if I understand you correctly, yes. Using tokens as you did in the scripting above. You can also perform various tasks by setting up your script and input format to do different things based on different conditions you specify.


Any way you can rephrase that?

#129401 06/09/05 02:54 AM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
put an example of what it is that you want to do (the text file you mentioned) and lets see what happens.

#129402 06/09/05 03:00 AM
Joined: Sep 2005
Posts: 14
C
Chappy Offline OP
Pikka bird
OP Offline
Pikka bird
C
Joined: Sep 2005
Posts: 14
for(var = 1; var < 5; inc var) {
msg # %var
}

so that it does the same as:

set %var 1
while(%var < 5) {
msg # %var
inc %var
}

#129403 06/09/05 03:30 AM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
Code:
/for {
  set %var1 $gettok($1-,1,59)
  set %var2 $gettok($1-,2,59)
  set %var3 $gettok($1-,3,59)
  set %var4 $gettok($1-,4,59)
  echo -a %var1 %var2 %var3 %var4
  while (%var1 %var2 %var3) {
    msg # test %var1 %var2 %var3 %var4
    %var4 %var1
  }
  unset %var*
}

output:

/for 1;<=;5;inc
1 <= 5 inc
<MikeChat> test 1 <= 5 inc
<MikeChat> test 2 <= 5 inc
<MikeChat> test 3 <= 5 inc
<MikeChat> test 4 <= 5 inc
<MikeChat> test 5 <= 5 inc

/for 5;>=;1;dec
5 >= 1 dec
<MikeChat> test 5 >= 1 dec
<MikeChat> test 4 >= 1 dec
<MikeChat> test 3 >= 1 dec
<MikeChat> test 2 >= 1 dec
<MikeChat> test 1 >= 1 dec

#129404 07/09/05 12:16 AM
Joined: Sep 2005
Posts: 14
C
Chappy Offline OP
Pikka bird
OP Offline
Pikka bird
C
Joined: Sep 2005
Posts: 14
Ok, that didnt help, but now I have a new problem.

/for $scriptline aliases.txt lol = 1; %lol < 5; inc %lol

is there anyway that I can send the text "%lol" rather than the value of %lol? Thanks again.

Last edited by Chappy; 07/09/05 12:19 AM.
#129405 07/09/05 12:35 AM
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
I didn't look up to see the code you're using and I'm sorry if I point out something that sounds similar to what you're tying to do but was unnecessary of me to say it.. smile

But can't you use $(%lol,0) ?

-Andy

#129406 07/09/05 01:07 AM
Joined: Sep 2005
Posts: 14
C
Chappy Offline OP
Pikka bird
OP Offline
Pikka bird
C
Joined: Sep 2005
Posts: 14
Thanks a bunch for the help. I think now it'll finally give me a fairly solid for loop structure.

#129407 07/09/05 05:36 AM
Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
Would you mind posting the final code and an example of its use syntax when it is complete, i was about to code something similar when i saw this, so it would save me some time.


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
#129408 07/09/05 11:46 AM
Joined: Sep 2005
Posts: 14
C
Chappy Offline OP
Pikka bird
OP Offline
Pikka bird
C
Joined: Sep 2005
Posts: 14
I was going to post it.... but I just gave up. After working on it for at least 5 hours, and finally getting a small, but difficult problem, I just said *beep* it. But here's the final code:

Code:
/for {
  if ($1 isnum) {
    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" format. Each statement seperated by commas.
        while ($gettok(%tok, %subplace, 44) != $null) {
          set %subtok $remove($gettok(%tok, %subplace, 44),$chr(32))

          set $+(%,$gettok(%subtok,1,61)) $gettok(%subtok,2,61)
          inc %subplace
        }
      }
      else if (%place == 2) {
        set %tok $gettok($3-,%place,59)

        set %evalfirst $gettok(%tok,1,32)
        set %evalmid $gettok(%tok,2,32)
        set %evallast $gettok(%tok,3,32)
        set %evalwhile $gettok(%tok,1,32) $gettok(%tok,2,32) $gettok(%tok,3,32)

      }
      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)) {
      write for.txt $read($2,%forcount)
      msg # $read($2,%forcount)
      inc %forcount
    }
    msg # %evalfirst %evalmid %evallast

    while (%evalwhile) {
      echo -a got here
      set %forcount 1

      while ($read(for.txt,%forcount) != $null) {
        msg # got here
        / $+ $read(for.txt,%forcount)
        / $+ %exec
        inc %forcount
      }
    }
  }
}
 


under the format:

Code:
/testing {
  for $scriptline aliases.txt lol = 3; %lol &lt; 5 ;inc %lol
  say hi 
  :FOREND
}  


As you can see, it's a bit cluttered. $1 refers to the script line that the forloop is in. $2 refers to the _text_ file that the for loop is in (not the code for the for loop). You need to have the text script file that the forloop is in as a .txt. This takes out the "n539=".

The problem that I encountered was when a variable was being passed as a value, not a string, which isnt what I wanted. When I tried to fix it, everything jus got sour. So, here's the code, and good luck. And if you manage to fix it, please pst it back in here. I'd like to see my code NOT go to waste.

Last edited by Chappy; 07/09/05 11:48 AM.
#129409 07/09/05 03:43 PM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
Code:
/testing {
  for $scriptline aliases.txt lol = 3; $+(%,lol) &lt; 5 ;inc $+(%,lol)
  say hi 
  :FOREND
}  

also, could you post here your aliases.txt and any other text file this is to use.

#129410 07/09/05 04:01 PM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
also, its very important to look at what you are using to decide which part of the for alias runs, you have $3-

in your string "for $scriptline aliases.txt lol = 3; %lol < 5 ;inc %lol"
the $3 is "lol"

not sure why you have $scriptline in there either

try
/testingfor {
for 3; $+(%,lol) < 5 ;inc $+(%,lol)
say hi | ;has no relation to the "for alias"
; :FOREND <- does nothing here
}


Link Copied to Clipboard