Script problem

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Script problem

Post by demonnic »

Ok, you need to put the code you have for the out of potions trigger into the I quaffed trigger as well. If the only way you'll ever fail to quaff is if you don't have one, you may wish to set another variable for that as well. Though if you're gonna use automated potion quaffing, you may also just wanna stock up on a lot of potions. So for the trigger that you don't have any potions:

Trigger: no more potions
Code: [show] | [select all] lua
quaffing = false
havePotions = false
cecho("<red:yellow>YOU ARE OUT OF POTIONS. YOU SHOULD FIX THAT") --this step is optional, of course
Then the check for if you should quaff:

Trigger: your prompt trigger
Code: [show] | [select all] lua
if  (tonumber(matches[2]) < 800)  and (not quaffing) then
        display(tonumber(matches[2]))
        quaffing = true
        display(quaffing)
        sendall("get oil 2.leather", "quaff oil")
        quaffTimer = tempTimer(1,function() if quaffing then quaffing = false  end end)
end
And lastly on the healing success:

Trigger: I drank it!
Code: [show] | [select all] lua
quaffing = false
display(quaffing)
if quaffTimer ~= nil then 
  local didIKillIt = killTimer(quaffTimer) 
  quaffTimer = nil
  display(didIKillIt)
end

The display() function calls are to check the value of the variables(As per your last statement in previous post), so you can comment them out when you've got it working(anything after "--" (minus the quotes) in lua is a comment, see the comment after the optional color echo telling you you're out of potions). You may also want to declare them at the top of a script like so:
Code: [show] | [select all] lua
if quaffing == nil then quaffing = false end
if havePotions == nil then havePotions = true end
It can sometimes help to have one script object just to initialize variables. Just don't initialize them with simple statements like:

quaffing = false

Because if you do, and you click on the script in the middle of trying to quaff, it will set quaffing back to false and try to drink again. I know this isn't real likely, but if it did happen it'd drive you batty trying to figure out why.

Digital Ninja
Posts: 26
Joined: Mon Jun 07, 2010 1:43 am

Re: Script problem

Post by Digital Ninja »

Thanks!

Sorry, i'm not sure what i'm doing wrong! It does not even try and quaff the potion anymore. Literally just copy and pasted your code into three triggers then created a script where i put the two variables.

Strange thing was it worked ONE time, and then never again... I'm a bit clueless here ~ so im wondering if possibly that might mean it has something to do with the way the timer is working...? it's strange.

Also, i'm sure eventually it should start to work =) and so just to add more complexity AFTER it actually starts to work, I was curious about how to correctly use a VARIABLE in the "matching" section of a trigger?

What i'm intending is to have a variable called potion... i can create an alias, set it to potion = matches[2]
then use potion inside of the tigger call... and in the trigger body.

two parts:
In the Drink a Potion!
where you have sendall("get oil 2.leather", "quaff oil")

I thought it would be like:
sendall("get " ..potion.. " 2.leather", "quaff " ..potion)

but i'm not sure about the correct syntax...

also... in the other part. the actual TRIGGER matching:
The Quaff Healing Success! has an exact match set to:
You get a oil from leather bag...

how can i input a "variable" into that pattern matching? also i would assume it would need to change to perl regex
was thinking it could just be like "You get a" ..potion.. "from leather bag..."

not sure though about it.

Anyways. I'll keep playing around with this and see if I can get something to work. First step is actually getting the original idea working. All this new variable stuff is just extra toppings on the pizza =)

Hope that i'm not wearing you out too bad ;)
Cheers and thanks again really
Jonathan

Digital Ninja
Posts: 26
Joined: Mon Jun 07, 2010 1:43 am

Re: Script problem

Post by Digital Ninja »

And i'm playing with it some more... Does the order in which the "triggers" are laid out actually matter?
It seemed like when i moved the Healing Potions are Out! Trigger ABOVE the Drink Heal Potion and Quaff Healing Potion Success Triggers, then it started to actually work. HOWEVER, it went right back to the first problem. It was double quaffing still.

Here is what it looked like (the numbers and the true and false stuff is from the display)
Oh and as you can tell, the name of the potion changed, which is why i want to be able to put that into a variable like i mentioned in the last one.

Not only that, but if there are no potions in the bag... it goes into an infinite loop... Seems basically because the health is still below the threshold... so it keeps trying to get a potion to heal with. since it's not there, it tries over and over again. Oh and i had changed the threshold to under 1000, instead of 800... just because it was quicker.

< 976hp 1180mana 208mv >
976

true
get spider bag
quaff spider
You get A Spider Potion from leather bag.
false

true

< 976hp 1180mana 208mv >
976

true
get spider bag
quaff spider
You quaff A Spider Potion which dissolves.
You feel protected from poison.
Your muscles begin to bulge with magical strength.
The powerful healing of the gods heals your intense wounds.

< 1066hp 1180mana 208mv >
You get A Spider Potion from leather bag.
false

true

< 1066hp 1180mana 208mv >
You quaff A Spider Potion which dissolves.
You feel protected from poison.
Your muscles begin to bulge with magical strength.
The powerful healing of the gods heals your intense wounds.

< 1066hp 1180mana 208mv >

You hear a long howl in the distan
Last edited by Digital Ninja on Sun Jun 13, 2010 4:59 pm, edited 1 time in total.

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Script problem

Post by demonnic »

The order matters in so much as they are evaluated in order. Every trigger which is evaluated and matches on the line will fire, though, so be sure you don't have repeat triggers for things like drinking. If you export your profile (save profile as button) and attach it here, or send it to me at demonnic (at) gmail (dot) com then I can take a closer look. Also, what mud is this? Perhaps I can do some testing myself later on tonight, and post a solution.

Digital Ninja
Posts: 26
Joined: Mon Jun 07, 2010 1:43 am

Re: Script problem

Post by Digital Ninja »

Hey Demonnic! I'm sending you my profile and the actual Mud information too.
Thank you so much for your help
Jonathan

Post Reply