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 


Check Box Code
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sun Aug 07, 2016 7:48 am    Post subject: Check Box Code Reply with quote

I'm trying to code a check box, but it isn't working. The original code is old, but works.
Here is the additions this morning:
Code:
function FormShow(sender)
...
tChocoRace = createTimer(nil, true)
timer_onTimer(tChocoRace, CECheckbox6Click)
timer_setInterval(tChocoRace, 500)
timer_setEnabled(tChocoRace, false)
...
end--form_show
--
function CECheckbox6Click(sender)
boxstate = checkbox_getState(CheatPanel_CECheckbox6)
  if boxstate == cbChecked then
    timer_setEnabled(tChocoRace, true)
    local AL = getAddressList()
    cNo1curspeedaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 1 In Race Cur Speed")
    cNo1maxspeedaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 1 In Race Max Speed")
    cNo1maxsprintaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 1 In Race Max Sprint")
    cNo1curstamaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 1 In Race Cur Stamina")
    cNo1maxstamaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 1 In Race Max Stamina")
    cNo2curspeedaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 2 In Race Cur Speed")
    cNo2maxspeedaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 2 In Race Max Speed")
    cNo2maxsprintaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 2 In Race Max Sprint")
    cNo2curstamaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 2 In Race Cur Stamina")
    cNo2maxstamaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 2 In Race Max Stamina")
    cNo1maxsprint = memoryrecord_GetValue(cNo1maxsprintaddress)
    cNo1curspeed = memoryrecord_SetValue(cNo1curspeedaddress,cNo1maxsprint)
    cNo1maxstam = memoryrecordGetValue(AL, cNo1maxstamaddress)
    cNo1curstam = memoryrecordSetValue(cNo1curstamaddress, cNo1maxstam)
    cNo2curspeed = memoryrecord_GetValue(cNo2curspeedaddress)
    cNo2curspeed = memoryrecord_SetValue(cNo2curspeedaddress,cNo1curspeed*.25)
    cNo2maxstam = memoryrecordGetValue(AL, cNo1maxstam*.25)
    print("Choco 1 winner is enabled")
  else
    timer_setEnabled(tChocoRace, false)
    print("Choco 1 winner is not enabled")
  end
end

The game is Final Fantasy VII and I know the function isn't working as the print statement is never executed when the check box is checked(the state is 1 when checked)
What am I missing?
Back to top
View user's profile Send private message Yahoo Messenger
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Aug 07, 2016 8:16 am    Post subject: Reply with quote

Make sure CECheckbox6Click is assigned to your checkbox OnClick event.
Make sure CheatPanel_CECheckbox6 is an accessible object to your checkbox.
Make sure you click Execute script on the Cheat Table Lua Script.
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sun Aug 07, 2016 9:19 am    Post subject: Reply with quote

"Make sure CECheckbox6Click is assigned to your checkbox OnClick event."
No, I hadn't included the event on the object.
"Make sure CheatPanel_CECheckbox6 is an accessible object to your checkbox. "
I'm not sure what you mean?
"Make sure you click Execute script on the Cheat Table Lua Script."
The rest of the code all worked(s) in the code table.
Code:

function CECheckbox6Click(sender)
 boxstate = checkbox_getState(CheatPanel_CECheckbox6)
   if boxstate == cbChecked then
     timer_setEnabled(tChocoRace, true)
     local AL = getAddressList()
     cNo1curspeedaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 1 In Race Cur Speed")
     cNo1maxspeedaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 1 In Race Max Speed")
     cNo1maxsprintaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 1 In Race Max Sprint")
     cNo1curstamaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 1 In Race Cur Stamina")
     cNo1maxstamaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 1 In Race Max Stamina")
     cNo2curspeedaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 2 In Race Cur Speed")
     cNo2maxspeedaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 2 In Race Max Speed")
     cNo2maxsprintaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 2 In Race Max Sprint")
     cNo2curstamaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 2 In Race Cur Stamina")
     cNo2maxstamaddress = addresslist_getMemoryRecordByDescription(AL, "Choco 2 In Race Max Stamina")
     cNo1maxsprint = memoryrecord_getValue(AL, cNo1maxsprintaddress)
print(cNo1maxsprintaddress)
print(cNo1maxsprint)
     cNo1curspeed = memoryrecord_setValue(cNo1curspeedaddress,cNo1maxsprint)
     cNo1maxstam = memoryrecord_getValue(AL, cNo1maxstamaddress)
     cNo1curstam = memoryrecord_setValue(cNo1curstamaddress, cNo1maxstam)
     cNo2curspeed = memoryrecord_getValue(cNo2curspeedaddress)
     cNo2curspeed = memoryrecord_setValue(cNo2curspeedaddress,cNo1curspeed*.25)
     cNo2maxstam = memoryrecord_getValue(AL, cNo1maxstam*.25)
     print("Choco 1 winner is enabled")
   else
     timer_setEnabled(tChocoRace, false)
     print("Choco 1 winner is not enabled")
   end
 end

I had errors in the code that have been corrected and added a couple of print statements.
The first print statement works 16515BB0
The second print statement prints a blank line(assume this means nil)
So then what am I still missing?
Back to top
View user's profile Send private message Yahoo Messenger
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Aug 07, 2016 11:09 am    Post subject: Reply with quote

@DarkByte: Screw backwards compatibility, remove these functions from the library! Smile

memoryrecord_getValue only accepts a single parameter: the memory record. Remove the "AL" parameters.
Code:
memoryrecord_getValue(AL, cNo1maxsprintaddress)
...
memoryrecord_getValue(cNo1maxsprintaddress)


You should just be using:
Code:
cNo1maxsprintaddress = AL.getMemoryRecordByDescription("Choco 1 In Race Max Sprint")
print(cNo1maxsprintaddress.Value)
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sun Aug 07, 2016 11:22 am    Post subject: Reply with quote

Zanzer wrote:
@DarkByte: Screw backwards compatibility, remove these functions from the library! Smile

memoryrecord_getValue only accepts a single parameter: the memory record. Remove the "AL" parameters.
Code:
memoryrecord_getValue(AL, cNo1maxsprintaddress)
...
memoryrecord_getValue(cNo1maxsprintaddress)


If this is true then other statements in the whole code would not work, and that is not the case i.e.
Code:
maxhp1address = addresslist_getMemoryRecordByDescription(addresslist, "Hero Max Hit Pts (+h37)")
maxhp1 = memoryrecord_getValue(maxhp1address)

these and many more like it do work and don't give errors. I'm not arguing with you just stating what does/n't work in my example.
Quote:

You should just be using:
Code:
cNo1maxsprintaddress = AL.getMemoryRecordByDescription("Choco 1 In Race Max Sprint")
print(cNo1maxsprintaddress.Value)

I can accept your suggestion, but that would entail editing about 2800 lines of code, that mostly works, not the ones I'm asking, but the remainder.
Also it would include me trying to decipher what was to what is, to prevent any other errors. You were correct in the "backwards compatibility". All this code was worked out in 6.2 and running 6.3
Back to top
View user's profile Send private message Yahoo Messenger
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Aug 07, 2016 11:55 am    Post subject: Reply with quote

bknight2602 wrote:
If this is true then other statements in the whole code would not work, and that is not the case i.e.
Code:
maxhp1address = addresslist_getMemoryRecordByDescription(addresslist, "Hero Max Hit Pts (+h37)")
maxhp1 = memoryrecord_getValue(maxhp1address)

This is coded correctly. Notice how memoryrecord_getValue only contains one argument?
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sun Aug 07, 2016 12:06 pm    Post subject: Reply with quote

Zanzer wrote:
bknight2602 wrote:
If this is true then other statements in the whole code would not work, and that is not the case i.e.
Code:
maxhp1address = addresslist_getMemoryRecordByDescription(addresslist, "Hero Max Hit Pts (+h37)")
maxhp1 = memoryrecord_getValue(maxhp1address)

This is coded correctly. Notice how memoryrecord_getValue only contains one argument?

No coded exactly identical, but addresslist was used instead of AL
Code:
local adresslist = getAddressList()

Note the comma after addresslist.
Code:
maxhp1address = addresslist_getMemoryRecordByDescription(addresslist, "Hero Max Hit Pts (+h37)")


Currently changing my code to what you had suggested, I'll post an edit after I finish.

EDIT:
Code:

function CECheckbox6Click(sender)
boxstate = checkbox_getState(CheatPanel_CECheckbox6)
  if boxstate == cbChecked then
    timer_setEnabled(tChocoRace, true)
    local AL = getAddressList()
    cNo1curspeedaddress = AL.getMemoryRecordByDescription("Choco 1 In Race Cur Speed")
    cNo1maxsprintaddress = AL.getMemoryRecordByDescription("Choco 1 In Race Max Sprint")
    cNo1curstamaddress = AL.getMemoryRecordByDescription("Choco 1 In Race Cur Stamina")
    cNo1maxstamaddress = AL.getMemoryRecordByDescription("Choco 1 In Race Max Stamina")
    cNo2curspeedaddress = AL.getMemoryRecordByDescription("Choco 2 In Race Cur Speed")
    cNo2maxspeedaddress = AL.getMemoryRecordByDescription("Choco 2 In Race Max Speed")
    cNo2maxsprintaddress = AL.getMemoryRecordByDescription("Choco 2 In Race Max Sprint")
    cNo2curstamaddress = AL.getMemoryRecordByDescription("Choco 2 In Race Cur Stamina")
    cNo2maxstamaddress = AL.getMemoryRecordByDescription("Choco 2 In Race Max Stamina")
    cNo1maxsprint = memoryrecord_getValue(cNo1maxsprintaddress)
    cNo1curspeed = memoryrecord_setValue(cNo1curspeedaddress, tonumber(cNo1maxsprint))
    cNo1maxstam = memoryrecord_getValue(cNo2maxstamaddress)
    cNo1curstam = memoryrecord_setValue(cNo1curstamaddress, tonumber(cNo1maxstam))
    cNo2curspeed = memoryrecord_setValue(cNo2curspeedaddress,tonumber(cNo1curspeed)*.25)
    cNo2maxstam = memoryrecord_getValue(tonumber(cNo1maxstam)*.25)
    print("Choco 1 winner is enabled")
  else
    timer_setEnabled(tChocoRace, false)
    print("Choco 1 winner is not enabled")
  end
end


When the check box is check I get an error message:
999: attempt to perform arithmetic on a nil value
This is line 999
cNo2curspeed = memoryrecord_setValue(cNo2curspeedaddress,tonumber(cNo1curspeed)*.25)


Last edited by bknight2602 on Sun Aug 07, 2016 12:26 pm; edited 1 time in total
Back to top
View user's profile Send private message Yahoo Messenger
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Aug 07, 2016 12:15 pm    Post subject: Reply with quote

You're comparing the wrong function. I said memoryrecord_getValue.

Yours vs Theirs:
Code:
cNo1maxsprint = memoryrecord_getValue(AL           , cNo1maxsprintaddress) -- yours
maxhp1        = memoryrecord_getValue(maxhp1address                      ) -- theirs


Wrong vs Right:
Code:
cNo1maxsprint = memoryrecord_getValue(AL, cNo1maxsprintaddress) -- wrong
cNo1maxsprint = memoryrecord_getValue(cNo1maxsprintaddress) -- right
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sun Aug 07, 2016 12:38 pm    Post subject: Reply with quote

See my edited code and results above.
Back to top
View user's profile Send private message Yahoo Messenger
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Aug 07, 2016 8:26 pm    Post subject: Reply with quote

memoryrecord_SetValue doesn't return anything, of course it's nil.
Code:
cNo1curspeed = memoryrecord_SetValue(cNo1curspeedaddress,cNo1maxsprint)
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sun Aug 07, 2016 10:35 pm    Post subject: Reply with quote

Zanzer wrote:
memoryrecord_SetValue doesn't return anything, of course it's nil.
Code:
cNo1curspeed = memoryrecord_SetValue(cNo1curspeedaddress,cNo1maxsprint)


Thanks, but that is not the error line
This line is where the error is occurring.
Code:
cNo2curspeed = memoryrecord_setValue(cNo2curspeedaddress,tonumber(cNo1curspeed)*.25)

Here is the error:
999: attempt to perform arithmetic on a nil value

The one you posted seems to work, as there are no errors noted on that line.
Back to top
View user's profile Send private message Yahoo Messenger
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Aug 07, 2016 10:57 pm    Post subject: Reply with quote

Maybe someone else can take a crack at explaining this to him. I'm out.
Back to top
View user's profile Send private message
cooleko
Grandmaster Cheater
Reputation: 11

Joined: 04 May 2016
Posts: 717

PostPosted: Mon Aug 08, 2016 12:56 am    Post subject: Reply with quote

bknight2602 wrote:
Zanzer wrote:
memoryrecord_SetValue doesn't return anything, of course it's nil.
Code:
cNo1curspeed = memoryrecord_SetValue(cNo1curspeedaddress,cNo1maxsprint)


Thanks, but that is not the error line
This line is where the error is occurring.
cNo2curspeed = memoryrecord_setValue(cNo2curspeedaddress,tonumber(cNo1curspeed)*.25)
Here is the error:
999: attempt to perform arithmetic on a nil value

The one you posted seems to work, as there are no errors noted on that line.


Stop ignoring the advice. Your error is because of it. Fix your think.

Quote:
memoryrecord_SetValue doesn't return anything, of course it's nil.


One more time, because your think has a kink:
memoryrecord_setValue() DOESNT RETURN VALUES
You set cNo1curspeed EQUAL to memoryrecord_setValue() which DOESNT RETURN VALUES
You then attempt to perform math on cNo1curspeed, which doesnt exist (aka nil), because memoryrecord_setValue() DOESNT RETURN VALUES.
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Mon Aug 08, 2016 6:45 am    Post subject: Reply with quote

This statement sets a value for a variable cNo1curspeed
Code:
cNo1curspeed = memoryrecord_setValue(cNo1curspeedaddress, tonumber(cNo1maxsprint))

Does it not?
I'm not understanding what both of you seem to understand so easily.
Back to top
View user's profile Send private message Yahoo Messenger
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Mon Aug 08, 2016 9:37 am    Post subject: Reply with quote

Zanzer wrote:
@DarkByte: Screw backwards compatibility, remove these functions from the library! Smile
+1
The old functions make it easier for people who don't know what they're doing to get misconceptions.

If you set a memory record's value, you are assigning some string to that property. You are not getting that property.
Code:
memrec.Value = '5'  -- does not return anything; it's an assignment
print(memrec.Value)   -- prints out the value, because you're only getting the value (not assigning anything to it)

print(memrec.Value = '5')  -- gives you a generic syntax error because Lua expects you to know that this doesn't make any sense

The variable cNo1curspeed is nil because of that, which is causing the error later on in your script.

By the way, this line of code near the end should be an obvious error:
Code:
cNo2maxstam = memoryrecord_getValue(tonumber(cNo1maxstam)*.25)

_________________
I don't know where I'm going, but I'll figure it out when I get there.
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
Goto page 1, 2  Next
Page 1 of 2

 
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