mIRC Homepage
Posted By: Navid Loop problems - 17/07/05 07:40 AM
Hi, smile with another problem, probably not that major.
here is my code:
Code:
on 1:Text:!listmoves:*: {
  var %topics = $ini(Bot_Stats\Moves.stats,0)
  var %use = 0
  while (%use != %topics) {
    inc %use
    %var %userline = $ini(Bot_Stats\Moves.stats,%use),effect)
  notice $nick 4 $ini(Bot_Stats\Moves.stats,%use) $+ :12 %userline }
  unset %userline
}


It shows something like this:
Punch:
Kick:

in Moves.stats, I have this:
Code:
[Punch] 
Available=Yes
effect=Level:1 Damage:2 Cost:$10
Cost=0
Base-Damage=2
Level=1

[Kick]
Available=Yes
effect=Level:1 Damage:2 Cost:$10
Cost=0
Base-Damage=2
Level=1


I want to make it so it shows something like this:
Punch: Level:1 Damage:2 Cost:$10
Kick: Level:1 Damage:2 Cost:$10
energybeam: Level:1 Damage:2 Cost:$10
and if under Available it has a =No then it doesn't show in the !listmoves.

Sorry for askign a lot guys this is the only place I get some answer, reading the /help over and over doesnt help here.
Any help is most appriciated.


EDIT: + here is teh error msg i get:
= Unknown command
-
= Unknown command
-
= Unknown command
-
= Unknown command
-
Posted By: NeoN Re: Loop problems - 17/07/05 10:07 AM
I'll show the syntax errors in your code first:

Code:
on 1:Text:!listmoves:*: {
  var %topics = $ini(Bot_Stats\Moves.stats,0)
  var %use = 0
  while (%use != %topics) {
    inc %use
    [color:red]%[/color]var %userline = $ini[color:green]([/color]Bot_Stats\Moves.stats,%use[color:red])[/color],effect[color:green])[/color]
  notice $nick 4 $ini(Bot_Stats\Moves.stats,%use) $+ :12 %userline [color:red]}[/color]
  unset %userline
}


1. %var instead of var:

Instead of using the command var, it will try to execute whatever is in the variable %var (nothing in this case). Since %userline is also empty, "=" becomes the command for this line. Hence the "= Unknown command" error.

2. On the same line you have an excess )

3. Not a syntax error, but if you put the } on the next line, your code is indented properly (everything inside the while loop starts at the same position). It makes it more readable.

If you change these errors, your script "works". That is, it executes without errors, but it still doesn't give you the output you want. You'll get:

Punch: 2
Kick: 2

$ini() only gives you the name of a section/item if you provide it a number (position), or the position of a section/item if you give it a name. That's where the 2 comes from, "effect" is the 2nd item in each section.
To read the values you need $readini().

Here is some sample code that does what you want:

Code:
on 1:Text:!listmoves:*: {
  var %topics = $ini(Moves.stats,0)
  var %use = 1
  var %section, %userline, %avail
  while (%use <= %topics) {
    [color:green]; get the name of the section on position "%use" (kick, punch, ...)[/color]
    %section = $ini(Moves.stats,%use)
    [color:green]; read Yes/No for "available"[/color]
    %avail = $readini(Moves.stats,np,%section,available)
    if (%avail == Yes) {
      [color:green]; read the value for "effect"[/color]
      %userline = $readini(Moves.stats,np,%section,effect)
      notice $nick %section $+ : %userline
    }
    inc %use
  }
}


Hope this helps.
Posted By: Navid Re: Loop problems - 18/07/05 01:22 AM
Takes a lot NeOn it worked!. smile I can learn a heck lot from you guys. smile
Just one more question.
I have a characters.ini and in that I have
[chr1]
chrname=Chr1
hp=50
energy=20
attack=20
defense=15
planet=earth

and I wish to write a code that it will directly writeini in $nick.ini all that I have under the topic [chr1].
I thought of /copy but I'm not sure how to use that (there is no examples on /help).
Thanks for helping around smile
© mIRC Discussion Forums