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 


Variables are being ignored.

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

Joined: 08 Jun 2018
Posts: 64

PostPosted: Wed Nov 14, 2018 4:39 pm    Post subject: Variables are being ignored. Reply with quote

Im working on a new script and I've encountered a problem I haven't seen before. Im using the word Travelling and assigning values ranging from 1 to 30 Eg

if isKeyPressed (0x77) then
Travelling = 1
end

if (Travelling == 1) and (BlaBla == DoDo) then
DoStuff
Travelling = 2
elseif (Travelling == 2) and (BlaBla == DoDo) then
DoStuff
Travelling = 3
elseif and so on


So yeah. Im encountering the problem where even if Travelling equals 3 at the time then the part of the code that requires it to equal 2 or 1 is still running. Im not sure why this is happening. Could someone enlighten me. I'd really appreciate it.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4711

PostPosted: Wed Nov 14, 2018 5:42 pm    Post subject: Reply with quote

It won't.
Code:
local i = 3
if i == 1 then
  print'1'
elseif i == 2 then
  print'2'
elseif i == 3 then
  print'3'
end
This code will always print 3.

You're doing something else causing it to screw up. If you would like help with that, please provide an SSCCE instead of pseudocode.

_________________
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
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25820
Location: The netherlands

PostPosted: Thu Nov 15, 2018 1:54 am    Post subject: Reply with quote

Does it run in a loop ? (timer/thread)
and is BlaBla ever the same as DoDo

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
MikeNoey
Advanced Cheater
Reputation: 0

Joined: 08 Jun 2018
Posts: 64

PostPosted: Fri Nov 16, 2018 5:31 am    Post subject: Reply with quote

Thanks for the input guys. Sadly I was making a really simple mistake with OR statements. That's how some lines were being run repeatedly. I hadn't worked with OR statements before. Pretty much the part of the code with the Travelling variable that also had OR statements were being run repeatedly and ignoring the Travelling part.


if (Travelling == 2) and (Xcoords > 100) or (Zcoords > 600) or (Xcoords < 200) or (Zcoords < 800) then
Travelling = 3



by changing it to

if (Travelling == 2) then
if (Xcoords > 100) or (Zcoords > 600) or (Xcoords < 200) or (Zcoords < 800) then
Travelling = 3
end
elseif and so on

It was finally working for me.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4711

PostPosted: Fri Nov 16, 2018 9:22 am    Post subject: Reply with quote

and takes precedence over or.
Code:
a and b or c or d  ==  ((a and b) or c) or d

Use parenthesis to explicitly dictate precedence.
Code:
a and (b or c or d)

_________________
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
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