Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Can't figure out simple greater than and less than on string

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
violaboy13
Newbie cheater
Reputation: 0

Joined: 23 Jul 2014
Posts: 11

PostPosted: Wed Oct 12, 2016 11:03 pm    Post subject: Can't figure out simple greater than and less than on string Reply with quote

I have an edit box that I'm putting numbers into. I want only numbers 10-40. Any number outside this range should turn the box red and write #20 into the address. This code sort of works but I can still put numbers 100 and above into the box and they will be written to the address instead of #20. Shouldn't the var3 > "40" take care of any number above 40? What am I doing wrong? Thanks for any help provided.


local number = readBytes("mainapp.exe+13A84CC",1)
var3=(setProperty(MaddenScripts_CEEdit3,"Text",(number)))

function AccClock(sender)
var3=(getProperty(MaddenScripts_CEEdit3,"Text"))
var3=(string.match(var3,"^%d+"))

if (var3 < "10") then
WriteBytes(0x17A84CC,"20")
control_setColor(MaddenScripts_CEEdit3, 255)

elseif (var3 > "40") then
WriteBytes(0x17A84CC,"20")
control_setColor(MaddenScripts_CEEdit3, 255)

else
WriteBytes(0x17A84CC,var3)
control_setColor(MaddenScripts_CEEdit3, 000255000)
end
end
Back to top
View user's profile Send private message
predprey
Master Cheater
Reputation: 24

Joined: 08 Oct 2015
Posts: 486

PostPosted: Wed Oct 12, 2016 11:57 pm    Post subject: Reply with quote

1. what is wrong is you are comparing var3 with a string because of the quotation marks.

2. this is right: var3 < 10; var3 > 40
this is wrong: var3 < "10"; var3 > "40"

3. BOOMZZZ
Back to top
View user's profile Send private message
violaboy13
Newbie cheater
Reputation: 0

Joined: 23 Jul 2014
Posts: 11

PostPosted: Thu Oct 13, 2016 7:04 am    Post subject: Reply with quote

I thought that too, but if I take away the quotation marks I get an error that I'm comparing a string (var3) with a number. How do I convert the string (var3) to a number so that I'm comparing a number with a number? Thanks

Edit: OK I figured it out; I needed this code to convert string to number

var3=tonumber(var3)


I knew this had to be a simple solution; thanks for your help.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites