How to save value from trigger as number

Post Reply
jwrobbs
Posts: 21
Joined: Sat Sep 23, 2017 1:26 am

How to save value from trigger as number

Post 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?

jwrobbs
Posts: 21
Joined: Sat Sep 23, 2017 1:26 am

Re: How to save value from trigger as number

Post by jwrobbs »

You have to use tonumber() when you assign the value.

Example x = tonumbner(matched[2])

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: How to save value from trigger as number

Post by Vadi »


Post Reply