Log In  

Can i do something like this or is there another way?

if btnp(4) then if btn(1) then player1_x+=10 elseif btn(0) player1_x-=10 end

if my code is too messy than just know that i'm trying to do 'If X is clicked and Right is down, then teleport 10 pixels to the right, if X is clicked and Left is down, then teleport 10 pixels to the left'

P#90065 2021-04-06 08:33

I logged in as fast as I could;

You can use and, or, () and probably some others to manipulate bools!!!!

Oh ya I was forgetting NOT too!!!

P#90066 2021-04-06 09:09 ( Edited 2021-04-06 09:13)

You can absolutely do this, yes. You are just missing a second "end" keyword to close the outermost "if".

If you do not wish to nest "if"s, you can use constructs with "and" and "or" to achieve the same thing:

if btnp(4) then player1_x += btn(1) and 10 or btn(0) and -10 or 0 end

In this specific case you can also use the "btn()" bitfield return value (this code deliberately does nothing if both left and right are pressed):

if btnp(4) then player1_x += ({-10,10})[btn() & 3] or 0 end
P#90067 2021-04-06 10:03

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2021-04-16 12:02 | 0.010s | 4194k | Q:16