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
➜ Run-time error in custom script
Run-time error in custom script
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Xandler
(52 posts) Bio
|
Date
| Thu 11 Jan 2018 09:22 PM (UTC) |
Message
| I currently have a script set up to pick up a certain item and count it so I can keep track of how many of these said items I have, the problem I have encountered is I'm getting a run-time error when the script runs (it counts the item and everything). The following is the error I receive:
Run-time error
Plugin: dragonball_checker (called from world: Dragonball Evolution)
Immediate execution
[string "Trigger: "]:4: attempt to compare number with string
stack traceback:
[string "Trigger: "]:4: in main chunk
The coding I have is as follows:
pkdball1 = tonumber (GetVariable ("pkdball1")) or 0
pkdball1 = pkdball1 + 1
SetVariable ("pkdball1", pkdball1)
if GetVariable("pkdball1") >= 1 then
if GetVariable("pkdball2") >= 1 then
if GetVariable("pkdball3") >= 1 then
if GetVariable("pkdball4") >= 1 then
if GetVariable("pkdball5") >= 1 then
if GetVariable("pkdball6") >= 1 then
if GetVariable("pkdball7") >= 1 then
Send ("ewish agility")
end
end
end
end
end
end
end
Just wondering how I can fix this issue. The ifchecks are for when I gather all the items and complete a "wish" for that option. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Thu 11 Jan 2018 10:24 PM (UTC) |
Message
| GetVariable returns a string, so you need to convert them back into numbers:
if tonumber (GetVariable("pkdball1")) >= 1 then
if tonumber (GetVariable("pkdball2")) >= 1 then
if tonumber (GetVariable("pkdball3")) >= 1 then
...
And if you really want send "ewish agility" if they are all greater than or equal to one, use "and" rather than a lot of deeply-nested ifs:
if tonumber (GetVariable("pkdball1")) >= 1 and
tonumber (GetVariable("pkdball2")) >= 1 and
tonumber (GetVariable("pkdball3")) >= 1 and
tonumber (GetVariable("pkdball4")) >= 1 and
tonumber (GetVariable("pkdball5")) >= 1 and
tonumber (GetVariable("pkdball6")) >= 1 and
tonumber (GetVariable("pkdball7")) >= 1 then
Send ("ewish agility")
end
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Xandler
(52 posts) Bio
|
Date
| Reply #3 on Sat 13 Jan 2018 04:30 PM (UTC) Amended on Sun 14 Jan 2018 04:14 AM (UTC) by Nick Gammon
|
Message
| Having a bit of trouble with this part of the script working:
<trigger
enabled="y"
expand_variables="y"
group="dragonballs"
match="^\[Quest\]\: <Your Character here> has made a wish with the Dragonballs\!$"
regexp="y"
send_to="12"
sequence="100"
>
<send>pkdball1 = tonumber (GetVariable ("pkdball1")) or 0
pkdball1 = pkdball1 - 1
SetVariable ("pkdball1", pkdball1)
pkdball2 = tonumber (GetVariable ("pkdball2")) or 0
pkdball2 = pkdball2 - 1
SetVariable ("pkdball2", pkdball2)
pkdball3 = tonumber (GetVariable ("pkdball3")) or 0
pkdball3 = pkdball3 - 1
SetVariable ("pkdball3", pkdball3)
pkdball4 = tonumber (GetVariable ("pkdball4")) or 0
pkdball4 = pkdball4 - 1
SetVariable ("pkdball4", pkdball4)
pkdball5 = tonumber (GetVariable ("pkdball5")) or 0
pkdball5 = pkdball5 - 1
SetVariable ("pkdball5", pkdball5)
pkdball6 = tonumber (GetVariable ("pkdball6")) or 0
pkdball6 = pkdball6 - 1
SetVariable ("pkdball6", pkdball6)
pkdball7 = tonumber (GetVariable ("pkdball7")) or 0
pkdball7 = pkdball7 - 1
SetVariable ("pkdball7", pkdball7)</send>
Basically inside the brackets will be the character name and when that message comes up it SHOULD take one number off EVERY item required for the wish, but for some reason its not quite working, all the variables (pkdball1-7) remain unchanged (until I have to manually reset it). I may just have it in wrong (I've been testing every now and again), but getting all 7 is kinda rare so I haven't been able to specifically test this portion that thoroughly. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #4 on Sun 14 Jan 2018 04:20 AM (UTC) |
Message
| Is it actually firing? Try putting a print into the script and seeing if that appears (or change the colour of the matching line to yellow or something).
When I tested it all of those variables were set (and became -1). When I tested it again they all became -2, so in principle it is working. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Xandler
(52 posts) Bio
|
Date
| Reply #5 on Sun 14 Jan 2018 09:14 PM (UTC) |
Message
| Well, like I said, I have been playing around with it (each time I get all 7 items and do a wish), and if it doesn't work like its supposed to, I tinker with it a little. (Is there a way to force it to fire, so I can see if it works?) | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #6 on Sun 14 Jan 2018 09:36 PM (UTC) |
Message
| Yep, go to the Game menu -> Test Trigger (Shift + Ctrl + F12).
Then enter the line you are supposed to see. Put a newline before and after it (use Ctrl+Enter to do that). |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Xandler
(52 posts) Bio
|
Date
| Reply #7 on Mon 15 Jan 2018 04:40 PM (UTC) |
Message
| Awesome! Learning new things every day with mushclient. On a sidenote, I managed to get the last item I needed for the wish and it worked like its supposed to! | Top |
|
Posted by
| Xandler
(52 posts) Bio
|
Date
| Reply #8 on Mon 15 Jan 2018 05:13 PM (UTC) |
Message
| Working on adding other things to it, I want to add
|>Intellect: *
but it shares a line with something else, but I want to cut it off after that asterik...I know its something simple but I can't seem to figure it out. I thought the $ symbol ended the line so it wouldn't copy the rest of the line, therefore:
|>Intellect: *$
but that doesn't seem to work :( | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #9 on Mon 15 Jan 2018 08:42 PM (UTC) |
Message
| Remember that asterisk is a "magic" character. If you want to go up to an asterisk put a backslash before it. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Xandler
(52 posts) Bio
|
Date
| Reply #10 on Tue 16 Jan 2018 02:59 AM (UTC) Amended on Tue 16 Jan 2018 03:55 AM (UTC) by Nick Gammon
|
Message
| Hrm....I cant get it to work right, its either showing the entire line, or nothing.
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="|>Intellect: \*"
send_to="9"
sequence="100"
variable="CharInt"
>
<send>%1</send>
</trigger>
</triggers>
That version leaves the variable blank, if I take out the "\" it reproduces the entire line. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #11 on Tue 16 Jan 2018 03:59 AM (UTC) |
Message
| That's not a regexp, so you don't need the backslash. Can you show what you are trying to match on?
Does the asterisk represent the intelligence? And there is other stuff after it? Try using a script then you can choose what goes into the variable, like this:
<triggers>
<trigger
enabled="y"
match="|>Intellect: * *"
send_to="12"
sequence="100"
variable="CharInt"
>
<send>
SetVariable ("CharInt", "%1")
</send>
</trigger>
</triggers>
 |
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
|
That sets the variable CharInt to the first wildcard, and ignores the other stuff. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Xandler
(52 posts) Bio
|
Date
| Reply #12 on Tue 16 Jan 2018 04:05 AM (UTC) |
Message
| |>Intellect: 100 Rage: 100
Just trying to match the Intellect, and yes there's more after it, and yes, the wildcard is the number, but what you had posted works just fine, not sure if there's a better workaround for that or not. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #13 on Tue 16 Jan 2018 04:13 AM (UTC) |
Message
| Since you know the line looks like that it is clearer to match on it:
Now, you don't actually need to use the second wildcard. Also you may have an issue with spaces. Since you have a fixed number of spaces the matching will be out with an intellect of 3 digits compared to 1 digit. A regular expression would be better:
^\|\>Intellect:\s+(\d+)\s+Rage:\s+(\d+)$
(Check the "regular expression" box)
The \s+ stuff matches one or more spaces, so the exact number isn't critical any more. Also the \d+ matches one or more digits so it wouldn't match on (say) letters.
See here for more details: http://www.gammon.com.au/regexp |
- 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.
32,678 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top