Page 1 of 1

How to save value from trigger as number

Posted: Wed Jan 16, 2019 1:09 am
by jwrobbs
Here's a simple one for you.

What I'm doing
I'm capturing numbers from my prompt, storing the data in variables, and using the data in gauges.

What's happening
I ran my scripts and got the error about comparing strings and numbers. So I went and set all the variables to number and saved it 100 different ways. The scripts worked perfectly. But as soon as I tried it live, the variables switched from number to string.

Trigger: HP: (\d*)\/(\d*) MN: (\d*)\/(\d*) MV: (\d*)\/(\d*) G: (\d*) TNL: (\d*) T: (\d*)
Prompt: HP: 45/45 MN: 103/103 MV: 111/111 G: 1004 TNL: 410 T: 12

Code excerpt:
hp = matches[2]
hpx = matches[3]
mn = matches[4]
mnx = matches[5]

The big question
How do I tell Mudlet that those variables are numbers?

Re: How to save value from trigger as number

Posted: Wed Jan 16, 2019 1:32 am
by jwrobbs
You have to use tonumber() when you assign the value.

Example x = tonumbner(matched[2])

Re: How to save value from trigger as number

Posted: Wed Jan 16, 2019 6:17 am
by Vadi