$arg() - Help

Help section from before the user variable changes that broke all macros

Moderator: MacroQuest Developers

kagonis
a hill giant
a hill giant
Posts: 228
Joined: Sat May 24, 2003 8:48 pm

$arg() - Help

Post by kagonis » Thu Aug 21, 2003 7:33 pm

I am trying to make a part that will allow for semi intelligent parsing of options, using a space seperated string, an example follows:

Code: Select all

/macro macro "option1=value1 option2=value2 option3=value3" "Some other parameter" "yet a parameter"
This should be handled by this following piece of code:

Code: Select all

/varset l1 1
:Options
	|** Tried to check for end of options here, to avoid a destop crash, but seems to be a problem with the $arg() **|
	/if "$arg($l1,"$p0")"=="" /goto :EndOptions

	|** Find the optionname of the string **|
	/varset l3 $left($instr("=","$arg($l1,"$p0")"),"$arg($l1,"$p0")")

	|** Find the value for the option **|
	/varset l4 $right($calc($strlen("$arg($l1,"$p0")")-$instr("=","$arg($l1,"$p0")")-1),$arg($l1,"$p0"))

	|** Assign values to their corresponding options **|
	/varset $l3 $l4

	/varadd l1 1
/if "$arg($l1,"$p0")"!="" /goto :Options
:EndOptions
Unfortunately this seems to crash the EQ client instantly to the desktop.
I tried working with simple /echo'ing directly from the EQ client, but this also crashed the client.
My question is, have I made some fatal, stupid, "Let me suck up all the memory due to a an endless loop" code, or something completely different? Or is the $arg() just FUBARed?

The problem comes not when it actually finds the split, but when it doesnt.

This is a working example:

Code: Select all

/echo Arg-test: $arg(2,"This is a string.")
Returns "is" as it should.

Code: Select all

/echo Arg-test: $arg(5,"This is a string.")
Crashes the client to the desktop.
How am I to know how many arguments (read: space seperated words) I have in my string? Cause as it is, this is the only way to avoid this crash, to simply not try and access a non-existing argument.

chimaera
a lesser mummy
a lesser mummy
Posts: 37
Joined: Fri Aug 01, 2003 4:14 pm

Post by chimaera » Fri Aug 22, 2003 7:43 am

How am I to know how many arguments (read: space seperated words) I have in my string? Cause as it is, this is the only way to avoid this crash, to simply not try and access a non-existing argument.

Code: Select all

/varset v1 0
/varset v2 1

:Stringparse
   /if n $v2==$strLen("This is a string.") /goto :Finished
   /if $mid(v2, 1, "This is a string.")~~" " /varadd v1 1
   /varadd v2 1
   /goto :Stringparse

:Finished

   /echo there is $v1 arguements in the current string.
There might be errors in this so plz double check :)

kagonis
a hill giant
a hill giant
Posts: 228
Joined: Sat May 24, 2003 8:48 pm

Post by kagonis » Fri Aug 22, 2003 7:01 pm

Thanks, this (with a few minor adjustments) works perfectly for counting the number of space seperated arguments in a string.

Code: Select all

Sub CountArgs
	/if "$p0"=="" {
		/echo Syntax: /call CountArgs "space seperated string of arguments"
		/endmacro
	}
	/varset l0 1
	/varset l1 1
	:Loop
		/if "$mid($int($l1),1,"$p0")"==" " /varadd l0 1
		/varadd l1 1
	/if n $l1<$strLen("$p0") /goto :Loop
/return $l0

kagonis
a hill giant
a hill giant
Posts: 228
Joined: Sat May 24, 2003 8:48 pm

Post by kagonis » Tue Aug 26, 2003 10:35 pm

Humm, the macro still crashes my client, I honestly can't seem to figure out what is causing it.
My logic tells me it should work, but as everyone knows, logic fails sometimes :p