View previous topic :: View next topic |
Author |
Message |
microsoftv Advanced Cheater Reputation: 0
Joined: 07 Apr 2016 Posts: 82 Location: U.S
|
Posted: Mon Aug 15, 2016 5:07 pm Post subject: Requesting help with following x coord of a player |
|
|
I'm wanting to make a follow"bot" that automatically follows the x coord of the player, I have the x coord and y coord, but not sure what to do with it. I tried doing a simple thing like
Code: | if isKeyPressed(VK_S) and p1x <= 40900000 then
doKeyPress(VK_LEFT)
if isKeyPressed(VK_S) and p1x >= 40900000 then
doKeyPress(VK_RIGHT)
end
end |
But of course that didn't work (not sure if it's even right, and I have p1x preset as readInteger).
If someone needs extra stuff to work with I can give my full code.
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Mon Aug 15, 2016 5:25 pm Post subject: |
|
|
I guess you need a bigger hint. No matter how hard you concentrate, that 8 will not magically change to a 3.
Code: | if bunted == 8 then
hitstun_countdown = 0
if bunted == 3 then |
|
|
Back to top |
|
|
microsoftv Advanced Cheater Reputation: 0
Joined: 07 Apr 2016 Posts: 82 Location: U.S
|
Posted: Mon Aug 15, 2016 6:06 pm Post subject: |
|
|
Zanzer wrote: | I guess you need a bigger hint. No matter how hard you concentrate, that 8 will not magically change to a 3.
Code: | if bunted == 8 then
hitstun_countdown = 0
if bunted == 3 then |
|
Not sure what you're getting at and why you posted it when i didn't even post that, but thanks anyways, and it changes periodically relative the the ball. so it has a chance to change the the value of 3 as it's a state that changes in different actions.
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Mon Aug 15, 2016 6:13 pm Post subject: |
|
|
As I'm trying to point out, the logical flow of your code goes as follows:
If the variable bunted is equal to 8, then I'm going to set hitstun_countdown equal to 0.
Next, given that we now know the variable bunted already equals 8, I'm going to check it again for the hell of it.
Is it equal to 3? Of course not, it still equals 8 when we last checked.
Now lets say the variable actually equals 3 at some point in time:
Does the variable bunted equal 8? No, then END! That's right, we never make it to the check for a value of 3.
Your if statements are NESTED and they are WRONG.
For every IF, you need an END to tell it when it's over.
It doesn't matter if you try to put a statement on the same line as the if.
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4300
|
Posted: Mon Aug 15, 2016 6:17 pm Post subject: |
|
|
Think about that logic a bit more.
Code: | if x == 1 then
print("1")
if x == 2 then
print("2")
end
end |
Try to find a circumstance where the above code will print "2".
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
microsoftv Advanced Cheater Reputation: 0
Joined: 07 Apr 2016 Posts: 82 Location: U.S
|
Posted: Mon Aug 15, 2016 7:05 pm Post subject: |
|
|
ParkourPenguin wrote: | Think about that logic a bit more.
Code: | if x == 1 then
print("1")
if x == 2 then
print("2")
end
end |
Try to find a circumstance where the above code will print "2". |
thank you for trying to teach me, i take that better than actual code just copy pasted.
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Mon Aug 15, 2016 7:14 pm Post subject: |
|
|
All he did was give you actual code and told you to think about it.
I don't understand how that's different from the actual code I posted, telling you to think.
Anyway, I'm out... happy hacking!
|
|
Back to top |
|
|
microsoftv Advanced Cheater Reputation: 0
Joined: 07 Apr 2016 Posts: 82 Location: U.S
|
Posted: Mon Aug 15, 2016 7:18 pm Post subject: |
|
|
Zanzer wrote: | As I'm trying to point out, the logical flow of your code goes as follows:
If the variable bunted is equal to 8, then I'm going to set hitstun_countdown equal to 0.
Next, given that we now know the variable bunted already equals 8, I'm going to check it again for the hell of it.
Is it equal to 3? Of course not, it still equals 8 when we last checked.
Now lets say the variable actually equals 3 at some point in time:
Does the variable bunted equal 8? No, then END! That's right, we never make it to the check for a value of 3.
Your if statements are NESTED and they are WRONG.
For every IF, you need an END to tell it when it's over.
It doesn't matter if you try to put a statement on the same line as the if. |
thanks for pointing this out, i usually only do the nesting if the if statements are involving the same thing, but what you said seems to say to me that it's completely unnecessary, although im still unsure where you got this, it was probably a mistake/mistype.
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Mon Aug 15, 2016 7:32 pm Post subject: |
|
|
I didn't just make the code up. I got it from your other post.
I reformatted it so that it would be easier for you to understand what the code is actually doing.
http://forum.cheatengine.org/viewtopic.php?p=5687285
Notice how you have the if-statement and the instruction on the same line?
Just because it's on the same line doesn't mean that's the end of the if-statement.
Code: | bunted = readInteger(getAddress("[ballstate]+144"))
if bunted == 8 then hitstun_countdown = 0
if bunted == 3 then hitstun_countdown = 20
bally = readInteger("[ballcoords]+1c") |
I have to assume the effect you actually wanted is:
Code: | bunted = readInteger(getAddress("[ballstate]+144"))
if bunted == 8 then hitstun_countdown = 0 end -- NOTE THE "END"
if bunted == 3 then hitstun_countdown = 20 end -- NOTE THE "END"
bally = readInteger("[ballcoords]+1c") |
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4300
|
Posted: Mon Aug 15, 2016 8:02 pm Post subject: |
|
|
Zanzer wrote: | I reformatted it so that it would be easier for you to understand what the code is actually doing. |
Emphasis on this.
microsoftv: If you properly indent your code, you can usually avoid these problems assuming you know Lua. If you don't know Lua, start learning- there are tons of tutorials everywhere. I'm sure you can also find extensive documentation on code formatting in general.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
microsoftv Advanced Cheater Reputation: 0
Joined: 07 Apr 2016 Posts: 82 Location: U.S
|
Posted: Mon Aug 15, 2016 8:30 pm Post subject: |
|
|
ParkourPenguin wrote: | Think about that logic a bit more.
Code: | if x == 1 then
print("1")
if x == 2 then
print("2")
end
end |
Try to find a circumstance where the above code will print "2". |
wouldnt it print only 2 or only 1? wouldnt print both right?
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4300
|
Posted: Mon Aug 15, 2016 8:34 pm Post subject: |
|
|
No. It will never print 2, regardless of what value is in x. As I said before, try it yourself.
Read and understand what Zanzer wrote. There is no better way to explain why you are wrong than what has already been said.
Zanzer wrote: | As I'm trying to point out, the logical flow of your code goes as follows:
If the variable bunted is equal to 8, then I'm going to set hitstun_countdown equal to 0.
Next, given that we now know the variable bunted already equals 8, I'm going to check it again for the hell of it.
Is it equal to 3? Of course not, it still equals 8 when we last checked.
Now lets say the variable actually equals 3 at some point in time:
Does the variable bunted equal 8? No, then END! That's right, we never make it to the check for a value of 3.
Your if statements are NESTED and they are WRONG.
For every IF, you need an END to tell it when it's over.
It doesn't matter if you try to put a statement on the same line as the if. |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
microsoftv Advanced Cheater Reputation: 0
Joined: 07 Apr 2016 Posts: 82 Location: U.S
|
Posted: Mon Aug 15, 2016 9:10 pm Post subject: |
|
|
ParkourPenguin wrote: | No. It will never print 2, regardless of what value is in x. As I said before, try it yourself.
Read and understand what Zanzer wrote. There is no better way to explain why you are wrong than what has already been said.
Zanzer wrote: | As I'm trying to point out, the logical flow of your code goes as follows:
If the variable bunted is equal to 8, then I'm going to set hitstun_countdown equal to 0.
Next, given that we now know the variable bunted already equals 8, I'm going to check it again for the hell of it.
Is it equal to 3? Of course not, it still equals 8 when we last checked.
Now lets say the variable actually equals 3 at some point in time:
Does the variable bunted equal 8? No, then END! That's right, we never make it to the check for a value of 3.
Your if statements are NESTED and they are WRONG.
For every IF, you need an END to tell it when it's over.
It doesn't matter if you try to put a statement on the same line as the if. |
|
Ok, I understand the process now. Thanks a lot both of you for explaining and helping, anyways, do either of you have anything to put on the forum post's title?
|
|
Back to top |
|
|
|