TLO Macro.Params broken with 9 - 12 patch

A forum for reporting bugs NOT related to custom plugins.

Moderator: MacroQuest Developers

dewey2461
Contributing Member
Contributing Member
Posts: 1759
Joined: Sun Apr 17, 2005 1:53 am

TLO Macro.Params broken with 9 - 12 patch

Post by dewey2461 » Wed Sep 13, 2017 6:22 pm

Call this with no arguments and I get two params, but both arg1 and arg2 are null. Easy to work around.

Code: Select all

Sub Main(string arg1,string arg2)

	/echo Macro.Params ${Macro.Params}
	/echo arg1 ${arg1}
	/echo arg2 ${arg2}

/return


JudgeD
a snow griffon
a snow griffon
Posts: 354
Joined: Sat Aug 18, 2012 8:07 pm

Re: TLO Macro.Params broken with 9 - 12 patch

Post by JudgeD » Wed Sep 13, 2017 7:51 pm

Macro.Params seems like a really weird thing to have available.

EqMule
Developer
Developer
Posts: 2697
Joined: Fri Jan 03, 2003 9:57 pm
Contact:

Re: TLO Macro.Params broken with 9 - 12 patch

Post by EqMule » Thu Sep 14, 2017 5:53 am

Not a bug, all parameters default to NULL when not supplied.
My status o/
If you like MQ2 and would like to contribute, please do. My goal is 25 donations per month.
So far I've received Image donations for this month's patches.

Bitcoin: 1Aq8ackjQ4f7AUvbUL7BE6oPfT8PmNP4Zq
Krono: PM me.
I can always use characters for testing, PM me if you can donate one.

dewey2461
Contributing Member
Contributing Member
Posts: 1759
Joined: Sun Apr 17, 2005 1:53 am

Re: TLO Macro.Params broken with 9 - 12 patch

Post by dewey2461 » Thu Sep 14, 2017 10:23 am

EqMule wrote:Not a bug, all parameters default to NULL when not supplied.
What should ${Macro.Params} be returning under the following conditions?

/mac test -> 2
/mac test p1 -> 2
/mac test p1 p2 -> 2
/mac test p1 p2 p3 -> 3

I modified my code to ignore Macro.Params.

EqMule
Developer
Developer
Posts: 2697
Joined: Fri Jan 03, 2003 9:57 pm
Contact:

Re: TLO Macro.Params broken with 9 - 12 patch

Post by EqMule » Thu Sep 14, 2017 12:33 pm

well you only have 2 params within your () so it should always return 2 unless somone calls that sub with 3 params which of course is stupid since the function clearly only takes 2 args...

but anyway... you could use Macro.Params to make sure you only get 2... and if someone supplies a third... /echo a warning then /endm

${Macro.Params} is most useful when you DONT know the number of args (the user?) supplied as in
/mac test.mac 1 2 3 4

Code: Select all

Sub Main
    /echo ${Macro.Params}
/return
which doesn't have a fancy (...)
My status o/
If you like MQ2 and would like to contribute, please do. My goal is 25 donations per month.
So far I've received Image donations for this month's patches.

Bitcoin: 1Aq8ackjQ4f7AUvbUL7BE6oPfT8PmNP4Zq
Krono: PM me.
I can always use characters for testing, PM me if you can donate one.

EqMule
Developer
Developer
Posts: 2697
Joined: Fri Jan 03, 2003 9:57 pm
Contact:

Re: TLO Macro.Params broken with 9 - 12 patch

Post by EqMule » Thu Sep 14, 2017 12:39 pm

and while we are on this topic, I am considering making the default just empty for strings and an actual number 0 if its an int, not sure yet.
My status o/
If you like MQ2 and would like to contribute, please do. My goal is 25 donations per month.
So far I've received Image donations for this month's patches.

Bitcoin: 1Aq8ackjQ4f7AUvbUL7BE6oPfT8PmNP4Zq
Krono: PM me.
I can always use characters for testing, PM me if you can donate one.

dewey2461
Contributing Member
Contributing Member
Posts: 1759
Joined: Sun Apr 17, 2005 1:53 am

Re: TLO Macro.Params broken with 9 - 12 patch

Post by dewey2461 » Thu Sep 14, 2017 12:54 pm

EqMule wrote: /mac test.mac 1 2 3 4

Code: Select all

Sub Main
    /echo ${Macro.Params}
/return
Given the above case, is there any way to get the actual command line arguments?

I think the TLO really should be ${Macro.Parms} = # of arguments, while ${Macro.Params[N]} returns the actual parameter, but it isn't implemented that way, and I'm probably the ONLY one who has used it in years so ...

EqMule
Developer
Developer
Posts: 2697
Joined: Fri Jan 03, 2003 9:57 pm
Contact:

Re: TLO Macro.Params broken with 9 - 12 patch

Post by EqMule » Thu Sep 14, 2017 3:47 pm

The macro above does return 4... which is the number of args supplied to it.
I'm not sure I understand your question

Updated:

Ok yes u want to know what ${Param<x>} actually contains?

Yeah that's easy: using the built in ${Param<x>} macro variables we can check this.

Code: Select all

| Macro Example to show how to get commandline variables without screwing up the macro engine with undeclared variables:
| EqMule 2017
#turbo

Sub Main
	/declare pi int local
	/declare NumParams int local
	
	| Check for command line variables
	/if (${Macro.Params}) {
		/varset NumParams ${Math.Calc[${Macro.Params}-1]}
	}
	/if (${Macro.Params}) {
		/for pi 0 to ${NumParams}
			/echo Commandline arg ${pi} is: ${Param${pi}}
		/next pi
	}
/return
if you do /mac testp.mac 1 2 "Hi There"
the macro will output
Commandline arg 0 is: 1
Commandline arg 1 is: 2
Commandline arg 2 is: Hi There
My status o/
If you like MQ2 and would like to contribute, please do. My goal is 25 donations per month.
So far I've received Image donations for this month's patches.

Bitcoin: 1Aq8ackjQ4f7AUvbUL7BE6oPfT8PmNP4Zq
Krono: PM me.
I can always use characters for testing, PM me if you can donate one.

dewey2461
Contributing Member
Contributing Member
Posts: 1759
Joined: Sun Apr 17, 2005 1:53 am

Re: TLO Macro.Params broken with 9 - 12 patch

Post by dewey2461 » Thu Sep 14, 2017 5:59 pm

I need to re-read the manual. Didn't know we had Param0, Param1, Param2 ...

Learn something new about MQ ... at least once a year :shock: