How To Do a if and command

so im trying to make it so if both the Y and the X cords = 5 it will stop the game if i put

on draw do
if then
if event.px==5 then
//all my game code

then even if just py = 5 it still stops.
is there a way to make it so that it only not does it when both are false?
Thanks in advance

Never Miind I solved myself

For anyone else finding this thread: there are no compound conditionals (if x and y then...) so you'll have to use nested if statements for "and" and elseif for "or". In the latter case, you can avoid repeating code by using a custom event handler. [Bad advice; see next comment from Shaun]

// "and"
if event.px == 5 then
  if == 5 then
    say "You're at row AND column 5!"

// "or"
if event.px == 5 then
  say "You're at row OR column 5!"
elseif == 5 then
  say "You're at row OR column 5!"
1 Like

A common PulpScript-ism is something like the following:

pass = 0
if x==5 then
  pass += 1
if y==5 then
  pass += 1

// AND
if pass==2 then
    // both

// OR
if pass>=1 then
    // one or the other

if pass==0 then
    // neither

(I’d avoid using a custom handler for this as there’s a lot of overhead associated with triggering an event.)


Thanks for the clarification, Shaun. I edited my comment.

Also for anyone else finding this thread, there is a way to simulate multiple AND conditionals in one if statement. Imagine we have 4 different variables and we want to check that all of them are equal:

  checkMultipleAnd = "{var1}{var1}{var1}{var1}"
  if checkMultipleAnd == "{var1}{var2}{var3}{var4}" then
    // do something

Although I don't know if this is better in terms of performance