pointers please..

Need help with a macro you are writing? Ask here!

Moderator: MacroQuest Developers

DLMac
decaying skeleton
decaying skeleton
Posts: 6
Joined: Tue May 04, 2004 2:51 am

pointers please..

Post by DLMac » Tue May 04, 2004 3:04 am

Hiyas!

I'm something of a noob to MQ - however have experience of programming with C and Java over some years so development isn't alien.

I've looked over the manual page, and also the some of the example macros but run in to problems.

First, let me just say, the "buffs" macro works fine, getting detailed times of how long is left. The "follow" macro doesn't, a series of messages about ( ) and so on. Threw me a curve ball as these are examples shipping with the code.

One of the objectives I hard, was to have a macro to do some imbues.

Sheer delight when i found this post imbue.mac (Imbue/Enchant macro) copied the macros and gave them a whirl. A stream of errors, surprising for scripts posted April 27th thought would work.

To confirm, the version of MQ I downloaded was the recommended source link and taken yesterday afternoon ( May 3rd ).

I don't expect folks to do things for me, but would appreciate some links that will show me some building blocks that work on MQ as of this month. I read in the news section, something about old macros being broken so finding points of reference is a bit hard. Would like to learn the "macro language" and hopefully contribute to this exciting project.

Thanks.

-DLMac.

CyberCide
a lesser mummy
a lesser mummy
Posts: 41
Joined: Wed Mar 10, 2004 1:48 pm
Location: Here lurking

Post by CyberCide » Tue May 04, 2004 3:24 am

Sheer delight when i found this post imbue.mac (Imbue/Enchant macro) copied the macros and gave them a whirl. A stream of errors, surprising for scripts posted April 27th thought would work.
This macro is pre-MQ2Datavar, so should be a simple fix. Look for the older style Parms @Param and change them to ${Param} and then debug the macro.

Good luck.

DLMac
decaying skeleton
decaying skeleton
Posts: 6
Joined: Tue May 04, 2004 2:51 am

Post by DLMac » Tue May 04, 2004 3:46 am

CyberCide wrote:
Sheer delight when i found this post imbue.mac (Imbue/Enchant macro) copied the macros and gave them a whirl. A stream of errors, surprising for scripts posted April 27th thought would work.
This macro is pre-MQ2Datavar, so should be a simple fix. Look for the older style Parms @Param and change them to ${Param} and then debug the macro.

Good luck.
Thanks. First I figure out what a "Param" is.

In the code I can see reference to variable "mount" being defined

Code: Select all

   /declare mount global 
I then see reference to it being used as:

Code: Select all

  /if  (@mount==0) /if (${Me.state[SIT]}==FALSE) /sit  
Are you saying that @mount is a 'Param' and needs to be changed to ${mount} , as in:

Code: Select all

  /if  (${mount}==0) /if (${Me.state[SIT]}==FALSE) /sit  

Digitalxero
a ghoul
a ghoul
Posts: 129
Joined: Tue Sep 10, 2002 5:01 pm

Post by Digitalxero » Tue May 04, 2004 4:30 am

Thats correct and you will also need to change the declare to something like

Code: Select all

/declare mount int outer
This sets it as an int type and outer is the same as the old global

DLMac
decaying skeleton
decaying skeleton
Posts: 6
Joined: Tue May 04, 2004 2:51 am

Post by DLMac » Tue May 04, 2004 4:32 am

Okay, been reading some more.

As well as the above question can someone please confirm this observation.

Current code reads

Code: Select all

    /if (${Defined[Param1]}) /varset itemname "@Param1" 
Should this be changed to read

Code: Select all

   /if (${Defined[Param1]}) /varset itemname ${Param1}
I'm a little thrown by the use of the " " as used to the content being a string literal.

Hope I'm on the right tracks of understanding the syntax changes. One other question to ask.

How white space is the macro language?

I'm used to writing:

Code: Select all

If ( condition )
{
    statements
}
but seem to find folks using

Code: Select all

If ( condition ) [b]{[/b]
    statements
}
Trivial it may be, but it's how I'm used to reading code and wondered how important it is. :roll:


Thanks.

-DLMac.

Goofmester1
a hill giant
a hill giant
Posts: 241
Joined: Thu Nov 06, 2003 4:26 am

Post by Goofmester1 » Tue May 04, 2004 6:47 am

The macro language before this month's addition of Datavars had some oddities like the "" around the params. What you changed to looks right to me.

White space seems to not have any effect. Having the { at the end of the statement instead of on the next line seems to help folks who aren't programmers by trade to keep in mind that the statement ties to the following lines if the { is at the end of the line. There are some nice history of Macroquest post popping up in different places.

LordGiddion
a snow griffon
a snow griffon
Posts: 352
Joined: Sat Sep 13, 2003 6:12 pm
Contact:

Post by LordGiddion » Tue May 04, 2004 9:09 am

hi DLMac welcome to MQ, let me see if I can help a bit here, People are mixing some terms Variables and Params, both are handled simular - a Param is a special variable - and both have had a revamp in the last month.
Not going way back in var cause this isn't the first time they've been changed, but recent history variables had 2 scopes global and local - Values returned by the Macroquest code were in the format $char(name) and variables you created or were passed into a sub were in the format @Varname. Now these things have been updated to be more object oriented. Variables have 3 scopes global which last as long as MQ is loaded and can be used to pass values between macros, Outer which are defined thoughout your entire macro and Local which are difeined only to the sub that called them. System returns are now ${Me.Name} and user vars are now ${varname} the advantages being that objects now have members so there is a lot more information you can access in your macros.
On the use of "" the varset command don't need quotes unless you want the quotes to be part of the string. However if you call a sub you may want quotes depending on how you want the sub to handle the string. In MQ spaces are used to seperate parameters rather then comas used in most languages (has to do with handling information from EQ) so in this code

Code: Select all

sub main
/declare MyVar string local
/varset  MyVar LordGiddion tells you got it now?

/call testsub "${MyVar}"
/call testsub ${MyVar}
/return

sub testsub
/echo ${Param0}
/return
First echo will display LordGiddion tells you got it now?
second echo will display LordGiddion

DLMac
decaying skeleton
decaying skeleton
Posts: 6
Joined: Tue May 04, 2004 2:51 am

Post by DLMac » Tue May 04, 2004 9:40 am

LordGiddion wrote:

Code: Select all

sub main
/declare MyVar string local
/varset  MyVar LordGiddion tells you got it now?

/call testsub "${MyVar}"
/call testsub ${MyVar}
/return

sub testsub
/echo ${Param0}
/return
First echo will display LordGiddion tells you got it now?
second echo will display LordGiddion
Okay, I can see what you mention.

Is this bad syntax?

Code: Select all

/declare MyVar string local
/varset  MyVar "LordGiddion tells you got it now?"
if the string can be set as above, i'd expect these lines..

Code: Select all

/call testsub "${MyVar}"
/call testsub ${MyVar}
to output...
LordGiddion tells you got it now?
LordGiddion tells you got it now?

Guessing I'll have some fun after work, with a few "hello worlds" and basic maths operations. Will take a while to get head around some of the language basics before i try to interact with game objects like inventory, containers, combine buttons and so on.

dman
a hill giant
a hill giant
Posts: 181
Joined: Fri Dec 05, 2003 12:54 pm

Post by dman » Tue May 04, 2004 10:01 am

Code:
/call testsub "${MyVar}"
/call testsub ${MyVar}



to output...
LordGiddion tells you got it now?
LordGiddion tells you got it now?

Guessing I'll have some fun after work, with a few "hello worlds" and basic maths operations. Will take a while to get head around some of the language basics before i try to interact with game objects like inventory, containers, combine buttons and so on.
The reason this outputs differently is the parser isn't passing the variable, but the text from the variable to the sub. The parser reads all ${} and replaces those directly with the values. So the parser reads

Code: Select all

/call testsub "${MyVar}"
as
/call testsub "LordGiddion tells you got it now?"
and

Code: Select all

/call testsub ${MyVar}
as
/call testsub LordGiddion tells you got it now?
When passing parameters to subs, spaces separate params unless enclosed by "" so those statements are different in use as well as syntax.

DLMac
decaying skeleton
decaying skeleton
Posts: 6
Joined: Tue May 04, 2004 2:51 am

...

Post by DLMac » Tue May 04, 2004 10:53 am

Okies I've given this whirl and not getting expected results.

Code: Select all

    /if (${Defined[Param1]}==FALSE) /call Syntax 

    /if (${Defined[Param1]}) /varset itemname ${Param1} 

    /echo ${Param0}
    /echo ${Param1}

    /varset spellname ${Param0} 

    /echo ${spellname}
based on launching the macro with:

/macro imbue "imbue emerald" "emerald"

The output received is:

[MQ2] imbue emerald
[MQ2] emerald
[MQ2] 0

So, I'm thrown why the "spellname" variable isn't being assigned the value of "Param0"

dman
a hill giant
a hill giant
Posts: 181
Joined: Fri Dec 05, 2003 12:54 pm

Post by dman » Tue May 04, 2004 11:02 am

without testing, the only thing I can think of is, do you have the variable declared as a string prior to varsetting and echoing it? It looks like you are declaring it as

Code: Select all

/declare spellname int outer
instead of

Code: Select all

/declare spellname outer
or

Code: Select all

/declare spellname string outer
In your case it appears the string is forced into the int value and MQ treats strings as 0 so its echoing correctly.

Preocts
a snow griffon
a snow griffon
Posts: 312
Joined: Thu Jan 29, 2004 1:02 pm

Post by Preocts » Tue May 04, 2004 12:43 pm

Without seeing more of the code you used I can only ramble about related subjects that might help.

Some of the new toys Lax has given us. Instead of /varset'ing your user var you can now set it the moment you declare it.

Code: Select all

/declare SpellName string local ${Param0}
Will set ${SpellName}==${Param0}

Or, if you like:

Code: Select all

/declare SpellName string local
/varset SpellName ${Param0}
Also, this is redundant.

Code: Select all

/if (${Defined[Param1]}==FALSE) /call Syntax 
${Defined[]} is a boolean value. Either True(1) or False(0). So:

Code: Select all

/if (${Defined[Param1]}) /echo Param1 is defined
/if (!${Defined[Param1]}) /echo Param1 is not defined
Not critical but it gives you an insight into uses /if's to their full power.

DLMac
decaying skeleton
decaying skeleton
Posts: 6
Joined: Tue May 04, 2004 2:51 am

....

Post by DLMac » Tue May 04, 2004 5:28 pm

erm.. :oops: ...rumbled.

It was indeed a data type error.

The original script reads

Code: Select all

   /declare mount global 
   /declare recast global 
   /declare mass global 
   /declare spellname global 
   /declare itemname global 
   /declare tmpspellname global 
Blindly following an earlier post without thinking, I'd changed the mentions of "global" to "int outer". Didn't notice the lack of data type in the former code and now I'd introduced one for each variable along with setting the scope.

For the record, the code now reads

Code: Select all

   /declare mount int outer 
   /declare recast int outer 
   /declare mass int outer 
   /declare spellname string outer  
   /declare itemname string outer 
   /declare tmpspellname string outer
Some good news though. I've hacked around with the script for long enough and it actually works! :)

The original script had a meditation section in it.

Code: Select all

Sub Event_NOMANA 
   /varset recast 1 

    /if  (@mount==0) /if (${Me.state[SIT]}==FALSE) /sit 
    
   :Loop 
      /delay 6s 

    /if ((${Me.CurrentMana})<(${Me.MaxMana})) /goto :Loop 

/return 
I thought nice but it is a hell of a lot of medding to full when it might not be necessary, especially if working an imbue mule. So I looked around for details on spell information and set the script to med until you have enough mana to cast the spell.

Code: Select all

Sub Event_NOMANA 
   /varset recast 1 

    /if  (${mount}==0) /if (${ Me.State[SIT] }==FALSE) /sit 

    /echo ${tmpspellname} needs ${Math.Calc[${Spell[${tmpspellname}].Mana}]} mana to cast.. medding
    
   :Loop 
      /echo current mana is.. ${Me.CurrentMana}
      /delay 6s 

     /if ((${Me.CurrentMana})<(${Math.Calc[${Spell[${tmpspellname}].Mana}]})) /goto :Loop 

/return 
Whilst the above works I've a feeling the "Math.Calc" is a sledgehammer to get the values represented as ints. So would appreciate some tips on that.

Thanks for the posts so far.

-DLMac.