• You've discovered RedGuides, an EverQuest multi-boxing and scripting community 🧙‍♀️⚙️. We want you to play several EQ characters at once, come join us and say hello! 👋

  • A TLP without truebox has thawed (Very Vanilla ready)
    Frostreaver

I need help with calling subs with parameters

cjt

Member
Joined
Oct 14, 2023
RedCents
271¢
I been trying to get this macro to work but I can't seem to find the right syntax for calling a sub using parameters, here is the macro:


[CODE title="Code"]
Sub Main
/declare index int outer
/declare fruit[2] string outer
/varset fruit[1] orange
/varset fruit[2] apple

:loop

/for index 1 to 2
/echo ${fruit[${index}]}
/call chomp(${fruit[${index}]})
/delay 1s
/next index

/goto :loop
/return

Sub chomp(Param0)
/echo ${Param0}
/return[/CODE]

What am I missing?
 
I been trying to get this macro to work but I can't seem to find the right syntax for calling a sub using parameters, here is the macro:


[CODE title="Code"]
Sub Main
/declare index int outer
/declare fruit[2] string outer
/varset fruit[1] orange
/varset fruit[2] apple

:loop

/for index 1 to 2
/echo ${fruit[${index}]}
/call chomp(${fruit[${index}]})
/delay 1s
/next index

/goto :loop
/return

Sub chomp(Param0)
/echo ${Param0}
/return[/CODE]

What am I missing?
Two things:
1. Subroutines (i.e. "chomp") have to be declared before used.
Move it to the top and should be good.

2. Calling the method doesn't need parentheses:
/call chomp ${fruit[${index}]}
 
Two things:
1. Subroutines (i.e. "chomp") have to be declared before used.
Move it to the top and should be good.

2. Calling the method doesn't need parentheses:
/call chomp ${fruit[${index}]}
Can you point me or show me how a sub should be declared?
 
Can you point me or show me how a sub should be declared?

Macro:
Code:
Sub chomp(Param0)
    /echo ${Param0}
/return

Sub Main
    /declare index             int outer
    /declare fruit[2]        string outer
    /varset fruit[1] orange
    /varset fruit[2] apple
   
    :loop
   
    /for index 1 to 2
        /echo ${fruit[${index}]}
        /call chomp ${fruit[${index}]}
        /delay 1s
    /next index
   
    /goto :loop
/return

But following up on acquietone's very accurate point - you definitely should start with Lua. For many reasons. The same script in Lua would be:
Lua:
local mq = require('mq')

local function chomp(fruit_name)
    printf('in chomp: %s', fruit_name)
end

local fruit = {}
fruit[1] = 'orange'
fruit[2] = 'apple'

-- or could do
-- local fruit = {'orange', 'apple'}

while(true) do
    for index=1,2 do
        print(fruit[index])
        chomp(fruit[index])
        mq.delay(1000)
    end
end
 
I been trying to get this macro to work but I can't seem to find the right syntax for calling a sub using parameters, here is the macro:


[CODE title="Code"]
Sub Main
/declare index int outer
/declare fruit[2] string outer
/varset fruit[1] orange
/varset fruit[2] apple

:loop

/for index 1 to 2
/echo ${fruit[${index}]}
/call chomp(${fruit[${index}]})
/delay 1s
/next index

/goto :loop
/return

Sub chomp(Param0)
/echo ${Param0}
/return[/CODE]

What am I missing?
Macros are an unconventional scripting language.

/call Function Param1 Param2 Param3 etc

You don't need to call your params param0, param1, etc. You can call them anything you want.

In the case of macros it's not needed that you declare the sub above the use of the sub....but you should be in the habit of doing so.

to answer your question

/call chomp ${fruit[${index}]}
 
Thanks CWTN, this is the right info and that's what I needed to overcome the issue.
 
If you're starting to learn the macro language, starting from Lua instead would be a lot less pain.
I been wondering about this and I have no idea of how it was engineered but to me it seems it is adding an extra layer on top of the original thing. Have the developers tested speed of execution of Lua vs MQ?
 
I been wondering about this and I have no idea of how it was engineered but to me it seems it is adding an extra layer on top of the original thing. Have the developers tested speed of execution of LUA vs MQ?
Nah it was just tossed in with no testing.

Lua is a well established programming language often embedded into games and you can see it used pretty widely, go look at any game with modding and you often see it. It also has ImGui support for writing UIs. You can also find all kinds of information on it online like stack overflow etc.
It hooks up to the MQ data types in a pretty natural way through the bindings and can access all the same data that macros can. You can also run several at once. It can also hook into more new stuff developed in MQ that will never have support added for macros like the new actor system stuff.

Macros are a home grown system that can only run one at a time and have like 20 years worth of bugs or gotchas or lost knowledge or things that work the way they do because of who maintained MQ at the time. You also can't find any answers about how to do anything in a macro without referring to an existing macro or an MQ related site.

Luas the way forward. The only macros now are the giant automation scripts that are being maintained because rewriting them in Lua would be a significant effort.
 
I been wondering about this and I have no idea of how it was engineered but to me it seems it is adding an extra layer on top of the original thing. Have the developers tested speed of execution of LUA vs MQ?
Back in the day, before luas could run under macroquest, I used my own macroscript macro. When coming back to the game after a long time off, I started to re-create my original macro again. But people here told me to do it with Lua instead. I had no idea what Lua was and to change language seemed like quite an intimidating project. But looking at a few existing luas and the VERY straight forward "convert macroscript to Lua" info in the documentation, it was actually not at all very difficult. Of course, I am still learning and am by no means anything but a novice, but I would still have to concur with everyone else here. Stop using macroscript, start using Lua. If you have any prior programming skills at all, Lua wont be difficult to manage. :)
 
Back in the day, before luas could run under macroquest, I used my own macroscript macro. When coming back to the game after a long time off, I started to re-create my original macro again. But people here told me to do it with Lua instead. I had no idea what lua was and to change language seemed like quite an intimidating project. But looking at a few existing luas and the VERY straight forward "convert macroscript to lua" info in the documentation, it was actually not at all very difficult. Of course, I am still learning and am by no means anything but a novice, but I would still have to concur with everyone else here. Stop using macroscript, start using lua. If you have any prior programming skills at all, Lua wont be difficult to manage. :)
Do you have any recommendations as to where to start documenting myself on how to convert my macros to Lua?
 
I been wondering about this and I have no idea of how it was engineered but to me it seems it is adding an extra layer on top of the original thing. Have the developers tested speed of execution of LUA vs MQ?

Macro is like getting beaten and robbed in a back alley and limping home with a broken leg.
Lua is like being loaded and driving a lamborghini. you can't really even compare the two
 
Macro is like getting beaten and robbed in a back alley and limping home with a broken leg.
Lua is like being loaded and driving a lamborghini. you can't really even compare the two
That's cool and seems Lua is well liked. I will try and see if I can learn it. Thanks for the input.
 
Macro:
Code:
Sub chomp(Param0)
    /echo ${Param0}
/return

Sub Main
    /declare index             int outer
    /declare fruit[2]        string outer
    /varset fruit[1] orange
    /varset fruit[2] apple
  
    :loop
  
    /for index 1 to 2
        /echo ${fruit[${index}]}
        /call chomp ${fruit[${index}]}
        /delay 1s
    /next index
  
    /goto :loop
/return

But following up on acquietone's very accurate point - you definitely should start with LUA. For many reasons. The same script in LUA would be:
Lua:
local mq = require('mq')

local function chomp(fruit_name)
    printf('in chomp: %s', fruit_name)
end

local fruit = {}
fruit[1] = 'orange'
fruit[2] = 'apple'

-- or could do
-- local fruit = {'orange', 'apple'}

while(true) do
    for index=1,2 do
        print(fruit[index])
        chomp(fruit[index])
        mq.delay(1000)
    end
end
wow, thanks for showing the difference between the two languages, Goldenfrog. I can see why using Lua is preferable. That syntax looks like a c language especially printf...

with regards on getting used to the old macro style.., this is what I think of:
Treat $ as a 'dereference' symbol on the variable. That means, every time you need the value in the variable, use the dollar sign. don't use the dollar sign when you are declaring or setting it. (/declare /varset)
 
Just want to add that the first thing I found in this new endeavor of mine is bad syntax. The help command in the LUA plugin commands page where it says to use the command "/Lua run help" is wrong. The right command is /Lua run -help or just /Lua with nothing else added which is what worked.

P.S. Also wanted to ask what version of Lua is being used? 5.2? 5.3?
 
You'll want to post to that resources discussion so one of the resource authors can update their documentation to reflect the correct option.
 
I need help with calling subs with parameters

Users who are viewing this thread

Back
Top
Cart