Difference in values

Posted by Silencher on Tue 18 Jun 2013 08:36 PM — 10 posts, 37,235 views.

#0
I want to find out how to use scripting to record an xp value to a variable when I type score and then the next time i type score take the new xp value and output the difference, and also retain the difference so that each time 'score' is typed the difference is added to an overall sum. How could I do something like this? So actually it would output 'sum' not difference. i can provide snippets of the mud code if needed? I think this may deal with regex which im not yet familiar with

I also want to know if instead i can make some kind of to next level script by setting a variable, lets call it 'goal' and subtract the difference from the goal until 'goal' is reached, at which point it should output 'you can gain a level!'

Australia Forum Administrator #1
Have you watched this?

http://www.gammon.com.au/forum/?id=10212

#2
I did! I didn't know it was something you did though.

I'll try to re-watch it, but I'm still not sure. I read your scripting thread as well and I'm having trouble with that too.

I guess I could do something like:

-----

alias name: score

(in body):

goal = 100
oldXp = 0
currentXp = 0

(somehow get the current xp and assign it to variable 'currentXp'. I'm having the most trouble with this because the Score is complicated and doesn't have it as 'Experience: (number)'.)

difference = currentXp - oldXp

if (difference == currentXp)
difference = 0 --This is so the first time 'score'
--is checked it doesn't make
--difference super high.
end

Note ("Since last time you've gained" + difference + "Xp!")

Oldxp = currentXp --So next time I type score the 'diff.'
--equation will run.
if goal <= currentXp
Note ("You can gain a level!")
else
Note ("You still have" + (goal - currentXp) + "Xp til
next level")
end

--------

Also, I'm not very well versed in Lua at all, I know basic, basic Java(not JavaScript). But the syntax in Lua I am not very comfortable with. I also miss my {}'s from Java, it seems unorganized to me.

How can I fix the above psuedo-code to be a working alias?
#3
Oops. Ignore me setting oldXp/currentXp = 0 at the top, that would screw the entire thing up for sure.
#4
Oops. Ignore me setting oldXp/currentXp = 0 at the top, that would screw the entire thing up for sure.
Australia Forum Administrator #5
Rather than posting snippets, how about the whole alias?

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
#6
Oh I haven't turned this into an alias. That was just my algorithm/psuedocode for what I want to do, I'm just not sure of the syntax to get it done.
Australia Forum Administrator #7
Have a stab at it and see what happens. Your code looks roughly OK except that the "if" statement needs a "then".

eg. Change:


if (difference == currentXp)
difference = 0 --This is so the first time 'score'
--is checked it doesn't make
--difference super high.
end


to:


if difference == currentXp then
  difference = 0 --This is so the first time 'score'
  --is checked it doesn't make
  --difference super high.
end


Also in Lua you concatenate with ".." so this line:


 Note ("Since last time you've gained" + difference + "Xp!")


should be:


 Note ("Since last time you've gained " .. difference .. " Xp!")


Alternatively, Note takes multiple arguments, so you could say:


Note ("Since last time you've gained ", difference, " Xp!")
#8
Oh I haven't turned this into an alias. That was just my algorithm/psuedocode for what I want to do, I'm just not sure of the syntax to get it done.
Australia Forum Administrator #9
Try experimenting. Nothing can go wrong, and you'll learn stuff. There are plenty of examples in the supplied plugins, and on this web site.