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 


Uncertain why one timer script works while a second doesn't.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
cooleko
Grandmaster Cheater
Reputation: 11

Joined: 04 May 2016
Posts: 717

PostPosted: Mon May 30, 2016 4:53 am    Post subject: Uncertain why one timer script works while a second doesn't. Reply with quote

I found two examples on the forums:

The first works fine:

Code:

cShip=0
lShip=0
timer = createTimer(nil,true)
timer_setInterval(timer,3000)
function CheckShip()
  cShip=getAddress("myShip") --myShip is a registered symbol
  Print(cShip)
  lShip=cShip
end

timer_onTimer(timer,CheckShip)


The Second just errors out on line 1:

Code:

LastShip = 0
CurrShip = 0
address = 0

function CheckShipStatus(t)
  CurrShip = d2h(readInteger(getAddress("myShip")))
  print("Current Ship: " .. CurrShip .. " & Last Ship: " .. LastShip)
  if (CurrShip ~= LastShip) and (CurrShip ~= 0) then
    address = d2h(readInteger([CurrShip +40]))
    print("First Pointer: " .. address)
    LastShip = CurrShip
  end
end

function ActivateTimer()
  t=createTimer(nil)
  t.OnTimer=CheckShipStatus
  t.Interval=3000
  t.Enabled=true
end


The second code is from DarkBytehttp://www.cheatengine.org/forum/viewtopic.php?t=573888&sid=cdec3905f7c29c50e06e2cd231954088

I have the appropriate enable/disable scripts for both to turn the timers on and off.

Why is the second code not working? The error is unexpected string '[' in line 1 which does not exist! I tried deleting everything but the function calls, but the error message applies to every line in the code.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Mon May 30, 2016 9:06 am    Post subject: Reply with quote

Code:
    address = d2h(readInteger([CurrShip +40]))

to
Code:
    address = d2h(readInteger("[CurrShip +40]"))

maybe even
Code:
    address = d2h(readInteger("CurrShip +40"))
Back to top
View user's profile Send private message
cooleko
Grandmaster Cheater
Reputation: 11

Joined: 04 May 2016
Posts: 717

PostPosted: Mon May 30, 2016 11:22 pm    Post subject: Reply with quote

Thank you, that is what was causing the error!
I appreciate your observation and assistance!
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