2017-12-17 11:10 CET

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000230Cheat Enginepublic2014-02-25 05:43
Reportermgr_inz_Player 
Assigned ToDark Byte 
PrioritynormalSeveritytweakReproducibilityalways
StatusresolvedResolutionfixed 
Platform32bitOSWindowsOS VersionXP
Summary0000230: timer, ontimer, sender, related to 0000211
DescriptionThis code:
####################################################
if toggle~=nil then toggle= not toggle else toggle=true end

function sharedOnTimer(timer)
  print(tostring(timer))
end

if Timer1~=nil then object_destroy(Timer1);Timer1=nil;end
if Timer2~=nil then object_destroy(Timer2);Timer2=nil;end

if toggle then
  Timer1 = createTimer(nil,false)
  timer_onTimer(Timer1,sharedOnTimer)
  timer_setInterval(Timer1,1000)
  timer_setEnabled(Timer1,true)

  Timer2 = createTimer(nil,false)
  timer_onTimer(Timer2,sharedOnTimer)
  timer_setInterval(Timer2,500)
  timer_setEnabled(Timer2,true)
  print('both timers enabled\r\n\r\n')
  print("print=", Timer1,Timer2)
  print("tostring=", tostring(Timer1),tostring(Timer2))
else
  print('both timers disabled')
end
####################################################


In old CE6.2, produce this output:
####################################################
both timers enabled

 
print= 000E0AD8 000DFE18
tostring= userdata: 000E0AD8 userdata: 000DFE18
userdata: 000DFE18
userdata: 000E0AD8
userdata: 000DFE18
userdata: 000DFE18
userdata: 000E0AD8
userdata: 000DFE18
userdata: 000DFE18
userdata: 000E0AD8
userdata: 000DFE18
both timers disabled
####################################################



With CE6.2+ (rev.1703), we have:
####################################################
both timers enabled

 
print= 000E6820 000E6880
tostring= userdata: 03A77230 userdata: 03A79E18
userdata: 03A7AED0
userdata: 03A7BE50
userdata: 03A7CDD0
userdata: 03A7DD50
userdata: 03A7ECD8
userdata: 03A7FC58
userdata: 03A80BD8
userdata: 03A81B58
userdata: 03A82AD8
userdata: 03A83A58
userdata: 03A849D8
userdata: 03A85958
userdata: 03A868D8
userdata: 03A87858
userdata: 03A887D8
both timers disabled
####################################################


Summary:

Old ce6.2, sender has only two values (because only two timers)
and this, numbers from "print" and "tostring" are equal:
print= 000E0AD8 000DFE18
tostring= userdata: 000E0AD8 userdata: 000DFE18


New ce6.2+, sender has many many values (!)
and this (values from print and tostring AREN'T equal):
print= 000E6820 000E6880
tostring= userdata: 03A77230 userdata: 03A79E18


Why I need "old behavior"? Example:
####################################################
if toggle~=nil then toggle= not toggle else toggle=true end

timerArg = {}
function sharedOnTimer(timer)
  print(timerArg[timer])
end

if Timer1~=nil then object_destroy(Timer1);Timer1=nil;end
if Timer2~=nil then object_destroy(Timer2);Timer2=nil;end

if toggle then
  Timer1 = createTimer(nil,false)
  timer_onTimer(Timer1,sharedOnTimer)
  timer_setInterval(Timer1,1000)
  timer_setEnabled(Timer1,true)

  Timer2 = createTimer(nil,false)
  timer_onTimer(Timer2,sharedOnTimer)
  timer_setInterval(Timer2,500)
  timer_setEnabled(Timer2,true)

  timerArg[Timer1] = "called by Timer1"
  timerArg[Timer2] = "called by Timer2"
  print('both timers enabled\r\n\r\n')
else
  print('both timers disabled')
end
####################################################


So I can use shared onTimer function. Of course for two timers we just write two onTimer. But what if we want to do for example 40 timers at runtime? It would be great if we could determine which timer called this function. I used Lua table for this, but in CE6.2+ this no longer works (above lua code doesn't print anything).



TagsNo tags attached.
Attached Files

-Relationships
+Relationships

-Notes

~0000484

Dark Byte (developer)

Last edited: 2013-03-17 23:51

You should be able to use == between sender and a timer you created earlier to see it's the same object.
the userdata is now a pointer to a pointer to the object, but if you compare between two class objects if it's the same the __eq metatable will check if it's the same object

Also, you should have used userDataToInteger(timer) in 6.2 instead of using the userdata as a map key

~0000485

mgr_inz_Player (reporter)

Last edited: 2013-03-18 02:02

OK, tried this in the last script:

Changing this:
print(timerArg[timer])
to:
print(timerArg[userDataToInteger(timer)])

And this:
timerArg[Timer1] = "called by Timer1"
timerArg[Timer2] = "called by Timer2"
to:
timerArg[userDataToInteger(Timer1)] = "called by Timer1"
timerArg[userDataToInteger(Timer2)] = "called by Timer2"

Solves everything.

Is there a better method?

+Notes

-Issue History
Date Modified Username Field Change
2013-03-16 04:15 mgr_inz_Player New Issue
2013-03-17 23:43 Dark Byte Note Added: 0000484
2013-03-17 23:43 Dark Byte Status new => acknowledged
2013-03-17 23:49 Dark Byte Note Edited: 0000484
2013-03-17 23:51 Dark Byte Note Edited: 0000484
2013-03-18 01:43 mgr_inz_Player Note Added: 0000485
2013-03-18 02:02 mgr_inz_Player Note Edited: 0000485
2014-02-25 05:43 Dark Byte Status acknowledged => resolved
2014-02-25 05:43 Dark Byte Resolution open => fixed
2014-02-25 05:43 Dark Byte Assigned To => Dark Byte
+Issue History