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 


Script Error: "'then' expected near '='"
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 Jul 18, 2021 11:36 am    Post subject: Script Error: "'then' expected near '='" Reply with quote

I have an if statement that is resulting in the "Script Error:[string " addresslist = getAddressList()
..."]:6: 'then' expected near '='"

I'm not understanding what is wrong.
Code:

    addresslist = getAddressList()
    TopHero = addresslist_getMemoryRecordByDescription(addresslist,"Top Char in Party")
    MidHero = addresslist_getMemoryRecordByDescription(addresslist,"Mid Char in Party")
    BtmHero = addresslist_getMemoryRecordByDescription(addresslist,"Btm Char in Party")
    print(TopHero.Value)
        if TopHero.value = 1 then
    battlescreen1maxhp = maxhp1
    battlescreenamaxmp = maxmp1
    elseif TopHero.value = 2 then
    battlescreen1maxhp = maxhp2
    battlescreenamaxmp = maxmp2
    elseif TopHero.value = 3 then
    battlescreen1maxhp = maxhp3
    battlescreenamaxmp = maxmp3
    elseif TopHero.value = 4 then
    battlescreen1maxhp = maxhp4
    battlescreenamaxmp = maxmp4
    elseif TopHero.value = 5 then
    battlescreen1maxhp = maxhp5
    battlescreenamaxmp = maxmp5
    elseif TopHero.value = 6 then
    battlescreen1maxhp = maxhp6
    battlescreenamaxmp = maxmp6
    elseif TopHero.value = 7 then
    battlescreen1maxhp = maxhp7
    battlescreenamaxmp = maxmp7
    elseif TopHero.value = 8 then
    battlescreen1maxhp = maxhp8
    battlescreenamaxmp = maxmp8
    elseif TopHero.value = 9 then
    battlescreen1maxhp = maxhp9
    battlescreenamaxmp = maxmp9
    end--if TopHero.value = 1 then
    memoryrecord_setValue(battlescreen1curhpaddress, battlescreen1maxhp)
    memoryrecord_setValue(battlescreen2curhpaddress, battlescreen2maxhp)
    memoryrecord_setValue(battlescreen3curhpaddress, battlescreen3maxhp)
    memoryrecord_setValue(battlescreen1curmpaddress, battlescreen1maxmp)
    memoryrecord_setValue(battlescreen2curmpaddress, battlescreen2maxmp)
    memoryrecord_setValue(battlescreen3curmpaddress, battlescreen3maxmp)

The print statement prints a 2, I'm guessing it is a sting
How do I fix this if error?
Back to top
View user's profile Send private message Yahoo Messenger
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Sun Jul 18, 2021 11:43 am    Post subject: Reply with quote

Error:

Code:
if ... = ... then


Fixed:

Code:
if ... == .. then
elseif ... == ... then
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sun Jul 18, 2021 11:53 am    Post subject: Reply with quote

Dumb me.
Thanks
Back to top
View user's profile Send private message Yahoo Messenger
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1055
Location: 0x90

PostPosted: Mon Jul 19, 2021 10:00 am    Post subject: Reply with quote

To explain what the actual problem was.

In Lua, the '=' is the assignment operator '==' is the equality operator.
Back to top
View user's profile Send private message
OswaldoAomine
Cheater
Reputation: 0

Joined: 07 Aug 2021
Posts: 38
Location: Yggdrasil

PostPosted: Sun Aug 22, 2021 12:19 pm    Post subject: Reply with quote

I have the same problem but in my case is when i put {$lua} say i have unexpected errro near "{".Please help me Arrow
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1055
Location: 0x90

PostPosted: Sun Aug 22, 2021 12:24 pm    Post subject: Reply with quote

You should show your script. How can you expect anyone to tell you how to fix the error without seeing your script?
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Sun Aug 22, 2021 12:58 pm    Post subject: Reply with quote

Question;
OswaldoAomine wrote:
I have the same problem but in my case is when i put {$lua} say i have unexpected errro near "{".Please help me Arrow



Reply;
FreeER wrote:
can you give more information than "I've tried everything and it doesn't work"? Like, an actual example of the simplest scripts you've tried that don't work? And maybe the name of the game (assuming you're not withholding it because it's an online game)

Also, in an AA script you have to use {$lua} before you can write lua code, eg.

Code:
[ENABLE]
{$lua}
print('you enabled me!')
{$asm}
// ^ ends lua section
[DISABLE]
{$lua}
print('Aw, try me again sometime!')
{$asm}


or
Code:
{$lua}
[ENABLE]
print('you enabled me!')
[DISABLE]
print('Aw, try me again sometime!')



Of course if you didn't create the scripts then it's possible they're out of date and aren't going to work just like AOB scripts would fail.


An example where the game name doesn't appear will save you time. (At least if it's a multiplayer online game scenario) Wink
Back to top
View user's profile Send private message
OswaldoAomine
Cheater
Reputation: 0

Joined: 07 Aug 2021
Posts: 38
Location: Yggdrasil

PostPosted: Sun Aug 22, 2021 2:16 pm    Post subject: Reply with quote

{$lua}

if syntaxcheck then return end


[ENABLE]
function setSpacetoZero()
local space="[[[[[[[Patron.exe+683D10]
local spacecheck=readfloat(space)

if spacecheck~=nil then
writefloat(space,0)
end
end

function timer()
t=createtimer()
t.OnTimer=setSpacetoZero
t.Interval=10
t.Enabled=true
end
timer()
[DISABLE]
t.destroy


This is the script.
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Sun Aug 22, 2021 3:58 pm    Post subject: Reply with quote

You can edit the "setSpacetoZero" code again.

The code below is working with the current state.

Code:
{$lua}

if syntaxcheck then return end

function setSpacetoZero()
local space=print("enabled") --[[Patron.exe+683D10]]
--local spacecheck=readfloat(space)

--if spacecheck~=nil then
--writefloat(space,0)
--end
end

if t then t.Destroy() t=nil end

t=createTimer()
t.Interval=1000

function EnableTmr() t.OnTimer=setSpacetoZero t.Enabled=true end

function DisableTmr() if t then t.Destroy() t=nil end end


[ENABLE]
EnableTmr()

[DISABLE]
DisableTmr()
Back to top
View user's profile Send private message
OswaldoAomine
Cheater
Reputation: 0

Joined: 07 Aug 2021
Posts: 38
Location: Yggdrasil

PostPosted: Sun Aug 22, 2021 5:33 pm    Post subject: Reply with quote

Thanks for the help i apreacite it.Cheers
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1055
Location: 0x90

PostPosted: Sun Aug 22, 2021 5:56 pm    Post subject: Reply with quote

I should point out that ByTransient's method of creating the timer passes no parent to the function and thus you are responsible for ensuring that the timer is destroyed.

It's far easier to pass getMainForm() as the parent, that way when you close Cheat Engine, the timer will also be destroyed.
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Sun Aug 22, 2021 6:08 pm    Post subject: Reply with quote

LeFiXER wrote:
I should point out that ByTransient's method of creating the timer passes no parent to the function and thus you are responsible for ensuring that the timer is destroyed.

It's far easier to pass getMainForm() as the parent, that way when you close Cheat Engine, the timer will also be destroyed.



What you want to say; That "createTimer()" is a build of Windows, not CE?

I think the objects it created were also destroyed when CE was closed.
Whereas; In the "Task Manager" you can test whether any "Timer" works after the CE is closed.

Additionally a "Timer"; I don't find it correct to bind to any form (MainForm or UDF1). Most of the time "TFont" errors are caused by binding "Timer" to the same form.

Of course the decision is yours, that's my opinion. Wink
Back to top
View user's profile Send private message
OswaldoAomine
Cheater
Reputation: 0

Joined: 07 Aug 2021
Posts: 38
Location: Yggdrasil

PostPosted: Sun Aug 22, 2021 6:39 pm    Post subject: Reply with quote

the problem keeps coming out I don't know why
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1055
Location: 0x90

PostPosted: Sun Aug 22, 2021 6:51 pm    Post subject: Reply with quote

ByTransient wrote:

What you want to say; That "createTimer()" is a build of Windows, not CE?

I think the objects it created were also destroyed when CE was closed.
Whereas; In the "Task Manager" you can test whether any "Timer" works after the CE is closed.

Additionally a "Timer"; I don't find it correct to bind to any form (MainForm or UDF1). Most of the time "TFont" errors are caused by binding "Timer" to the same form.

Of course the decision is yours, that's my opinion. Wink


What I want to say is that if you pass a nil owner for the timer then it is the user's responsibility to destroy the object when it is finished with. Cheat Engine will not know how to free the object since there is no valid handle. I am saying this because it states in the celua.txt document that you should be aware of this, as you will see below. Also, it's not to see if the timer will still work when Cheat Engine is closed or not, it's to do with "housekeeping" i.e. destroying objects properly also TFont is an entirely different class.

Quote:

createTimer(owner OPT, enabled OPT):
Creates a timer object. If enabled is not given it will be enabled by default (will start as soon as an onTimer event has been assigned)
Owner may be nil, but you will be responsible for destroying it instead of being the responsibility of the owner object)
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Sun Aug 22, 2021 7:10 pm    Post subject: Reply with quote

OK. However, I don't think it's right to assign an owner to the "Timer" object.

(This is still my opinion, it has caused a lot of problems in the past. If it's fixed now, I haven't tested it yet.)

The "Timer" object is being killed in my code.
Code:
function DisableTmr() if t then t.Destroy() t=nil end end


And "DISABLE" is running the final code.
Code:
[DISABLE]
DisableTmr()
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