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 


Question for mgr.inz.Player (or anyone else who can answer)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Thu Dec 29, 2016 5:29 am    Post subject: Question for mgr.inz.Player (or anyone else who can answer) Reply with quote

Sorry to create another topic so soon, I wanted to ask mgr.inz.Player directly but seems his PMs are blocked so hoping he or someone else can see this and answer. I'm using his example for saving/loading settings for CE trainers (http://forum.cheatengine.org/viewtopic.php?t=545361), but can't seem to figure out how to load a boolean value this way

Code:
function SaveSettingsClick()
  if TrainerOrigin then
    settingsFile = io.open(TrainerOrigin.."Settings.ini", "w")
    if (settingsFile ~= nil) then
      settingsFile:write(tostring(UDF1.CECheckbox1.Checked))
      settingsFile:close()
    end
  end
end

function LoadSettingsClick()
  if TrainerOrigin then
    settingsFile = io.open(TrainerOrigin.."Settings.ini", "r")
    if (settingsFile ~= nil) then
      UDF1.CECheckbox1.Checked = settingsFile:read()
      settingsFile:close()
    end
  end
end
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Thu Dec 29, 2016 10:13 am    Post subject: Reply with quote

Code:
print( type('true'=='true') )
print( type('true'=='false') )
print( type('true'=='whatever') )
>boolean
>boolean
>boolean

print( tostring('true'=='true') )
print( tostring('true'=='false') )
print( tostring('true'=='whatever') )
>true
>false
>false



So, your code needs only one small modification:
Code:
function SaveSettingsClick()
  if TrainerOrigin then
    settingsFile = io.open(TrainerOrigin.."Settings.ini", "w")
    if (settingsFile ~= nil) then
      settingsFile:write(tostring(UDF1.CECheckbox1.Checked))
      settingsFile:close()
    end
  end
end

function LoadSettingsClick()
  if TrainerOrigin then
    settingsFile = io.open(TrainerOrigin.."Settings.ini", "r")
    if (settingsFile ~= nil) then
      UDF1.CECheckbox1.Checked = ( settingsFile:read() == 'true' )    -----  here
      settingsFile:close()
    end
  end
end

_________________
Back to top
View user's profile Send private message MSN Messenger
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Thu Dec 29, 2016 1:34 pm    Post subject: Reply with quote

Thank you so much sir! Cheers Smile
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