Public Macros seems simple - passing vars
Reply
seems simple - passing vars
Hello,

Was hoping to get a tiny bump in the right direction.

I am trying to write a simple.. well in theory, macro. The idea is I want to be able to pick up an item and have it search for said item on my other toons that are logged in.

I get the item name and ID just find and can echo it .. no problems there.


Here is where I seem to just be getting my butt kicked.

Passing that ${itemName} to the others via BCAA command always comes back NULL for all the others. It would seem it is looking for that variable name locally rather then parsing it out to what its value is before sending the command.

Does that makes sense? How do you pass vars to other chars?

/varset ItemName ${Cursor}
/noparse /bcaa //bc ${ItemName}


in the Cmd window
Toon 0 "correct name
Rest toons
NULL

Any tips?

Thank you very much.


Macro
More +

sub main

| -=-=-=-=-=-=-=-=-=- |
|       DECLARES                  |
| -=-=-=-=-=-=-=-=-=- |
/deletevar ItemName
/declare ItemName string global
|only set to global for the last test I did.  Cant seem to access globs anywhere except one who sets it.

|Main Loop Starts and reruns from here
:MainLoop
/call CheckForItem
/doevents flush
/delay 10
/goto :MainLoop
/return


|/noparse /bcaa //bc ${FindItemBankCount[Thing IM looking for]}
|Zazuzh's Idol
|Zherozsh's Ring
|example items

Sub CheckForItem
/echo ItemName = ${ItemName}

/if (${Cursor.ID}) {
/varset ItemName ${Cursor}

/echo ItemName  = ${ItemName}
|this works

/echo Cursor = ${Cursor} / ID ${Cursor.ID}
|this works

|/noparse /bcaa //bc ${FindItem[${ItemName}]}
/noparse /bcaa //bc ${ItemName}
|comes back NULL on all but sender

}

/return
Sun Oct 25, 2015 1:47 pm
hmm
It appears as tho I need to use a ini.
Sun Oct 25, 2015 2:32 pm
done
Because I hate when some noob asks a question .. figures it out and never comes back to share the answer here you go

Macro
More +


sub main

| -=-=-=-=-=-=-=-=-=- |
|       DECLARES      |
| -=-=-=-=-=-=-=-=-=- |

/declare ItemName string outer
/declare FindIniFile string outer   find.ini

|Main Loop Starts and reruns from here
:MainLoop
/call CheckForItem
/doevents flush
/delay 50
/goto :MainLoop
/return

Sub CheckForItem
/varset ItemName ${Cursor}
/echo ==Waiting for Item==

/if (${Cursor.ID}) {
    /ini "${FindIniFile}" "LookingFor" " value1" "${ItemName}"
    /delay 3
    /noparse /bcaa //bc I have ${FindItemCount[${Ini[find.ini,LookingFor,value1]}]} and ${FindItemBankCount[${Ini[find.ini,LookingFor,value1]}]} in Bank
    } else {
    /echo No item on cursor.
    /ini "${FindIniFile}" "LookingFor" " value1" "No item on cursor"
}

/return
Sun Oct 25, 2015 3:31 pm
First, some background about variables...

Every instance of EQ - every character - is separated from every other character. CharacterA cannot look into the address space of CharacterB. CharacterA can see CharacterA's ${Me.Name} but cannot see CharacterB's ${Me.Name}.

Any workaround which we'll get to is just that: a workaround. Workarounds allow values to be shared between clients, but the original variable in memory is still hidden. Luckily, several workarounds exist. In no particular order: plugins, events and Ini files.

You have the Ini file route covered.

Plugins are the best solution if one exists for a particular piece of information. NetBots is a great example but NetBots doesn't share the name/id of held items.

That leaves events.

Macro
More +

#event CheckForItem "[MQ2] CheckForItem #1#"

Sub Main
   :mainloop
   /doevents
   /delay 1
   /goto :mainloop
/return

Sub Event_CheckForItem(string Line, string ItemName)
   /bc I have ${FindItemCount[=${ItemName}]} and ${FindItemBankCount[=${ItemName}]} in Bank
/return



/bcaa //echo CheckForItem ${Cursor.Name}

Run the macro on all characters then type in the above line. Upon seeing that line, the macro event will trigger and execute. The macro sits patiently until the trigger phrase is seen. The trigger phrase contains the necessary information.

This macro isn't exactly like the original. It's written as is to show the concept of macro events and also of passing variable values between clients.


Second, global variable scope...

Global scope means a variable exists "outside of any macro." It may help to think of variables such as ${Me.Name} and ${Cursor.ID} as global scope variables. They exist even when a macro isn't running.

Outer scope variables have macro scope. Macro scope variables will only exist while that macro is running on that character. Bye bye macro means bye bye variable.

Local scope variables only exist within a specific subroutine on a specific character. Leave that subroutine and you can no longer view or edit the local variable.

Neither global, outer, nor local can be used to pass variables between characters.
Sun Oct 25, 2015 6:16 pm
Senior Project Member
yup
Figured out the individuals .. didn't know what the globals were exactly but that was a great explanation. The chat event is cool but I wanted something easy where I wouldn't need to run macros on everyone.

Thanks for the info ..Makes sense.
Tue Oct 27, 2015 1:50 pm
Public Macros seems simple - passing vars
Reply