Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Difference in values
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Silencher
(55 posts) Bio
|
Date
| Tue 18 Jun 2013 08:36 PM (UTC) |
Message
| 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!'
| Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #1 on Wed 19 Jun 2013 05:56 AM (UTC) |
Message
| |
Posted by
| Silencher
(55 posts) Bio
|
Date
| Reply #2 on Wed 19 Jun 2013 06:46 AM (UTC) |
Message
| 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?
| Top |
|
Posted by
| Silencher
(55 posts) Bio
|
Date
| Reply #3 on Wed 19 Jun 2013 06:47 AM (UTC) |
Message
| Oops. Ignore me setting oldXp/currentXp = 0 at the top, that would screw the entire thing up for sure. | Top |
|
Posted by
| Silencher
(55 posts) Bio
|
Date
| Reply #4 on Wed 19 Jun 2013 07:10 AM (UTC) |
Message
| Oops. Ignore me setting oldXp/currentXp = 0 at the top, that would screw the entire thing up for sure. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #5 on Wed 19 Jun 2013 07:32 AM (UTC) |
Message
| Rather than posting snippets, how about the whole alias?
 |
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
|
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Silencher
(55 posts) Bio
|
Date
| Reply #6 on Wed 19 Jun 2013 07:51 AM (UTC) |
Message
| 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. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #7 on Thu 20 Jun 2013 06:15 AM (UTC) |
Message
| 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!")
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Silencher
(55 posts) Bio
|
Date
| Reply #8 on Wed 26 Jun 2013 10:37 PM (UTC) |
Message
| 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. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #9 on Wed 26 Jun 2013 11:39 PM (UTC) |
Message
| 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. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
27,410 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top