HOWTO: Set_Variable

free(?!) clues!

HOWTO: Set_Variable

Postby Kannkor » 06 Jan 2023, 02:22

Set_Variable and Get_Variable, are for scripters. If you're not a scripter, you likely won't need this.

Note: This is sudo code I wrote off the top of my head. There is the possibility there are typos etc. I will fix them as I'm aware of them, just keep that in mind.

This can be compared to a hash table/collection/key-value pair, that can be set by any session, but only read by the local session where the variable exists. You can, of course, make that variable on all sessions, so everyone can read it.

Using this for a local session only.
Sets the variable/value.
Code: Select all
OgreBotAPI:Set_Variable[ForWho,"VariableName","VariableValue"]

Checks to see if the variable exists (regardless of the value)
Code: Select all
echo ${OgreBotAPI.Get_VariableExists["VariableName"]}

Gets the value of the variable
Code: Select all
echo ${OgreBotAPI.Get_Variable["VariableName"]}

Clears a specific variable.
Code: Select all
OgreBotAPI:Clear_Variable[ForWho,"VariableName"]

Clears all variables
Code: Select all
OgreBotAPI:Clear_Variables[ForWho]


Lets come up with a random scenario. You're fighting a boss, who "says" something, and you need to keep track of this for later use. We'll keep it simple for now, and say this mob says "Reflecting now" and "No longer reflecting".

Some where we have the following snippit, that monitors chat events
Code: Select all
method EQ2_onIncomingText(string Message)
{
   if ${Message.Find["Reflecting now"](exists)}
             OgreBotAPI:Set_Variable[all,"MobName_Reflecting","TRUE"]
}


Then some where in your main loop, you could have something like this...
Code: Select all
 if ${OgreBotAPI.Get_VariableExists["MobName_Reflecting"]} && ${Bool[${OgreBotAPI.Get_Variable["MobName_Reflecting"]}]}
 {
    ; This means the mob is reflecting! We should do something, for simplicity, just going to target ourselves.
    target me
    ; Assuming this is in a loop, we likely don't want to spam this over and over and over, so we can clear the variable since we already handled this event.
   ; Keep in mind, there may be cases where you want to keep handling this over and over, so you may not clear the variable, that's entirely up to you.
   OgreBotAPI:Clear_Variable[all,"MobName_Reflecting"]
 }


Okay, now lets update our code to including when the mob is no longer reflecting. (Worth noting, we could be using the same variable and making it FALSE).
In this scenario, I'm using the variable MobName_StillReflecting, simply to show how to read something that is FALSE.
Code: Select all
method EQ2_onIncomingText(string Message)
{
   if ${Message.Find["Reflecting now"](exists)}
             OgreBotAPI:Set_Variable[all,"MobName_Reflecting","TRUE"]
       elseif ${Message.Find["No longer reflecting"](exists)}
             OgreBotAPI:Set_Variable[all,"MobName_StillReflecting","FALSE"]
}


And now back to our main loop
Code: Select all
 if ${OgreBotAPI.Get_VariableExists["MobName_Reflecting"]} && ${Bool[${OgreBotAPI.Get_Variable["MobName_Reflecting"]}]}
 {
    ; This means the mob is reflecting! We should do something, for simplicity, just going to target ourselves.
    target me
    ; Assuming this is in a loop, we likely don't want to spam this over and over and over, so we can clear the variable since we already handled this event.
   ; Keep in mind, there may be cases where you want to keep handling this over and over, so you may not clear the variable, that's entirely up to you.
   OgreBotAPI:Clear_Variable[all,"MobName_Reflecting"]
 }
 if ${OgreBotAPI.Get_VariableExists["MobName_StillReflecting"]} && !${Bool[${OgreBotAPI.Get_Variable["MobName_StillReflecting"]}]}
 {
    ; This means the mob is no longer reflecting! We should do something, for simplicity, just going to clear out target.
    OgreBotAPI:NoTarget
    ; Assuming this is in a loop, we likely don't want to spam this over and over and over, so we can clear the variable since we already handled this event.
   ; Keep in mind, there may be cases where you want to keep handling this over and over, so you may not clear the variable, that's entirely up to you.
   OgreBotAPI:Clear_Variable[all,"MobName_StillReflecting"]
 }
Kannkor
 
Posts: 354
Joined: 06 Nov 2013, 11:49

Re: HOWTO: Set_Variable

Postby Kannkor » 06 Jan 2023, 02:41

Using this for a multiple sessions.

Slightly different scenario.
The mob now says "Bard go right" and "Enchanter go left", HOWEVER, he only says this to a fighter! So your fighter must "tell" your bard and enchanter when to move, and when to move back.

Our chat events...
Code: Select all
method EQ2_onIncomingText(string Message)
{
   if ${Message.Find["Bard go right"](exists)}
             oc !c -Set_Variable igw:${Me.Name}+bard "MobName_BardMove" "TRUE"
       elseif ${Message.Find["Enchanter go left"](exists)}
             oc !c -Set_Variable igw:${Me.Name}+enchanter "MobName_EnchanterMove" "TRUE"
}


Here we have a few "depends how you want to do it".
In the above scenario, we are setting the variables ONLY on the bard or on the enchanter. This means no one else in the group would know if they are suppose to move or not. This greatly depends what you want to be doing, and how you're going to do it, if you want to set it up this way. Because our variables are very specific, we could just let the entire group know about it. Such as...
Code: Select all
oc !c -Set_Variable igw:${Me.Name} "MobName_BardMove" "TRUE"

In this basic example, it doesn't matter.

Now, we're going to run a script on the bard and enchanter, and they can handle the movement themselves (this works for more advanced things, such as go here, pick up an object, run over to xxx, set the object down, then run back to zzz).

In this side script, it could look something like this... I'm going use a variable from Ogre to check, ClassInfo has almost every type you could ever want. Feel free to try any of them.
Code: Select all
function main()
{
   if ${ClassInfo.IsBard} && ${OgreBotAPI.Get_VariableExists["MobName_BardMove"]} && ${Bool[${OgreBotAPI.Get_Variable["MobName_BardMove"]}]}
   {
      ; do stuff
      ; Example of clearing our the set_variable for ourselves
      OgreBotAPI:Clear_Variable[all,"MobName_BardMove"]
   }
   elseif ${ClassInfo.IsEnchanter} && ${OgreBotAPI.Get_VariableExists["MobName_EnchanterMove"]} && ${Bool[${OgreBotAPI.Get_Variable["MobName_EnchanterMove"]}]}
   {
      ; do stuff
      ; Example of clearing our the set_variable for our entire group
      oc !c -Clear_Variable igw:${Me.Name} "MobName_EnchanterMove"
   }
}


Then you can duplicate it again for when you need to move back.
Kannkor
 
Posts: 354
Joined: 06 Nov 2013, 11:49

Re: HOWTO: Set_Variable

Postby Kannkor » 06 Jan 2023, 03:03

One last one...
This one uses the new flag system, if you haven't read it...
https://forums.ogregaming.com/viewtopic.php?f=13&t=450

Going to skimp any details in the other two...
This boss says "one person go right and on person go left"

Lets assume there is an Ogrebot set up, and by default, the bard goes right, and the enchanter goes left.
This could be done, by saying, Flagtoon 1 is used for right, and Flagtoon 2 is used for left.

However, since we want to support the crazy people who don't have a bard, sigh. So we give instructions for the user, if they don't have a bard, to do the following:
Code: Select all
oc !c -flagtoon "igw:${Me.Name}+Kannkor" 1



Now, we need to update our check...
Code: Select all
if ${ClassInfo.IsBard} && ${OgreBotAPI.Get_VariableExists["MobName_BardMove"]} && ${Bool[${OgreBotAPI.Get_Variable["MobName_BardMove"]}]}

Becomes...
Code: Select all
if ${OgreBotAPI.ToonFlagged[1]} && ${OgreBotAPI.Get_VariableExists["MobName_BardMove"]} && ${Bool[${OgreBotAPI.Get_Variable["MobName_BardMove"]}]}
Kannkor
 
Posts: 354
Joined: 06 Nov 2013, 11:49


Return to Guides & Strats

Who is online

Users browsing this forum: No registered users and 1 guest

cron