Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Yes, Doc? I have a problem with conditionals

A topic by MrrPalta created 66 days ago Views: 147 Replies: 2
Viewing posts 1 to 2
(2 edits)

I’m not sure why this happens, but the logical OR operator "|" doesn't work for me when I use it in conditionals that check values for the same element. It’s hard to explain clearly, but I have a .deck file that illustrates exactly what I mean

My goal is for the program to correctly detect specific slider values specifically 1, 2, or 3 without issues. Instead, it only recognizes the first value specified in each condition and completely ignores any conditions listed after the "|" operator behavior I haven't encountered in other situations

I’d like to know if I’m doing something wrong or if this is a bug in the Decker language

https://drive.google.com/file/d/17Dmifnim6KHRAzyqlDFXGbcicy0nkMIS/view?usp=shari...

b:bar.value                  #bar<-slider  exit<-field
if     b=1|b=7          exit.text:1 #( ,1, , , , , ,7)
elseif b=0|b=3|b=4|b=6  exit.text:2 #(0, , ,3,4, ,6, )
elseif b=2|b=5          exit.text:3 #( , ,2, , ,5, , )
else        exit.text:"none" end    #Fail


no sé porqué sucede pero el logical or "|" no me funciona cuando quiero usarlo para condicionales los cuales requieren un valor sobre un mismo elemento, no se como explicarlo muy bien pero tengo un archivo .deck el cual puede servir como ejemplo a lo que me refiero

lo que quiero lograr es que con valores exacto de un slider, el programa te detecte sin problema cada uno con un 1, 2 o 3 pero en cambio, solo funciona con los primeros valores los cuales pongo en cada condición ignorando por completo las otras condiciones que vengan después de un "|" cuando en otros casos nunca me sucede eso

quiero saber si es un problema mio o es un error del lenguaje decker

Developer(+2)

For the benefit of other readers, the relevant script in the linked deck is

b:bar.value
if     b=1|b=7          exit.text:1 #( ,1, , , , , ,7)
elseif b=0|b=3|b=4|b=6  exit.text:2 #(0, , ,3,4, ,6, )
elseif b=2|b=5          exit.text:3 #( , ,2, , ,5, , )
else        exit.text:"none" end    #Fail

All operators in Lil have uniform right-to-left precedence unless overridden by parentheses.

An expression like

b=0|b=3|b=4|b=6

Is understood by Lil as equivalent to

b=(0|(b=(3|(b=(4|(b=6))))))

In this case, you'd probably get something closer to your intent by writing

(b=0)|(b=3)|(b=4)|(b=6)

Note that you could also write these kinds of test with the "in" operator:

b:bar.value
if     b in 1,7      exit.text:1
elseif b in 0,3,4,6  exit.text:2
elseif b in 2,5      exit.text:3
else                 exit.text:"none"
end

The "if ... elseif ... else ... end" structure evaluates to the last expression of each clause, so you could also lift out that assignment like so:

b:bar.value
exit.text:
if     b in 1,7      1
elseif b in 0,3,4,6  2
elseif b in 2,5      3
else                 "none"
end

Another alternative would be to use a "lookup table" instead of conditionals:

exit.text: (2,1,3,2,2,3,2,1)[bar.value]

To handle a default case for an invalid key- which will index out "nil"- we can use the "unless" operator:

exit.text: "none" unless (2,1,3,2,2,3,2,1)[bar.value]

If the keys for the lookup table aren't sequential integers, you could use the same approach with a dictionary instead of a list.

Does any of that help?

(+1)

Thanks! That helped :D