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"]
}