Log In  

Basic movement can be facilitated through:
if btn(0) then x-=1 end

But when I add sfx:

if btn(0) then x-=1 and sfx(0) end

It always generates an error as soon as that button 0 is pressed. Why is that? If x then y and z end. Is there something wrong with that syntax? Or is it related to sfx not working in this way?

And why is it when I clarify with brackets it doesn't even run!? Am I clarifying that my syntax is wrong before teh game starts? That's funny.
i.e.
if btn(0) then (x-=1 and sfx(0)) end

P#65973 2019-07-20 14:59 ( Edited 2019-07-20 15:01)

:: JasonE

You are misusing the keyword 'and'. Each statement will execute without using the word 'and', you just have to put them on their own line.

if btn(0) then
  x-=1
  sfx(0)
end

The keyword 'and' is what is called a logical operator. It is an operation on boolean values, true and false.
For example:

true and true == true
true and false == false
false and false == false
false and true == false

Statements such as comparisons eg. (x > 1) result in boolean values that can be used with the 'and' operator.

P#66697 2019-08-15 17:05

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-05-29 08:23 | 0.008s | 4194k | Q:11