Wallpaper Engine

Wallpaper Engine

View Stats:
( . )( . ) Mar 21, 2022 @ 9:44am
How does if() and var actually work?
I came to a situation where a dropdown menu is better for human compatibility than a slider.
There, I need 2 if()'s and in each I need to put 2 "OR" logic gates, but I don't know how to define 2 states?

For future reference, I would also like to know how to define 2 different user properties at once, either as AND or OR or with other logic gates?
Last edited by ( . )( . ); Mar 21, 2022 @ 11:08am
< >
Showing 1-9 of 9 comments
Biohazard  [developer] Mar 21, 2022 @ 10:17am 
In this case you could check a general JavaScript tutorial like this: https://www.freecodecamp.org/news/javascript-if-else-and-if-then-js-conditional-statements/ since if/else is a basic construct, not Wallpaper Engine specific, so any tutorial on JavaScript should be valid.

If you have trouble using Wallpaper Engine's user properties in your code though, it would be best if you could paste what you got so far and what you are trying to achieve exactly.
( . )( . ) Mar 21, 2022 @ 11:08am 
Thanks, but I just remembered what else I'm missing in the topic that is also pressing my intellect.

How does var work?
In CSS, it is a string that gets pasted into where ever I want and parsed after insertion, in which it inserts a hex color with a space at the end breaking the ability to add alpha channels without very elaborate CSS coding.
Right now, I put the var into the position script of one element. Would I be able to use that variable in other scripts in other elements?
I have also read about let, but what let refers to is unknown to me. (let's go!)
Rhy Mar 21, 2022 @ 11:59am 
Let and var are both used to declare variables, that is correct.
They don’t just store them as strings however, but moreso it depends on what you put into them. (Strings, numbers, objects..)

You cannot use them to transfer your variable to another script. For that to work you instead add your value to an object WE offers you.

shared.thingIwantToShare = 42;

This way you can call 42 from any other script using:

shared.thingIwantToShare;

(thingIwantToShare may be any name you want)
Let is basically the same as var, however it is only valid within a scope, for example a loop. The variable doesn’t exist outside of this block.

If that is confusing to you, search for examples linked above in the tutorials.

If you need any specific help on WE related code, the discord might have people willing to help.
Last edited by Rhy; Mar 21, 2022 @ 12:00pm
( . )( . ) Mar 21, 2022 @ 1:19pm 
I applied the if() rules from the link and it's still not working.
The first one is:
if(engine.userProperties.dropdown = 0 || engine.userProperties.dropdown = 1)
and the second is:
if(engine.userProperties.dropdown = 0 || engine.userProperties.dropdown = 2)
"else if" is not a solution to such a problem, since it will only allow 1 of many entries to work.

Where do I put the shared script?
The thingIwantToShare; is is a math equation.

I'd also like to know how I can add if()'s within the value defining code?
As the syntax is now, it tells me that this is not possible?
Rhy Mar 21, 2022 @ 2:31pm 
I'm very unsure of what you are trying to achieve.
it's ==, not = for the if statements.
== means you compare something.
= means you assign a variable.

Shared you put where you have a variable that needs to be shared with other scripts.

I dont know what you mean with the last one.
( . )( . ) Mar 21, 2022 @ 3:19pm 
Ohh, finally someone who knows something about the = & == things.
I previously was taught that there is no difference between = and == and was told to better use == in all cases.
And since the SceneScript uses mostly =...
But then again somewhere I saw someone use ===.
What does === mean? And does even more ='s exist or is it already overkill? xD

In BBTag, I can use {if;<statement>[;<comparator>;<2nd statement>];<true>[;<false>]} without limitation.
To assign a variable, I use {set;<scope><namespace>;<value>}
When I combine them, I would more likely put the if inside than outside to save space like
{void;{exec;import_utils}}{set;@example{userid};{if;{func.!?;{args;0}};==;true;{args;0};help}}
In the example code above, I injected my tag with external code that has usefull functions, and since it's prone to lots of breaks, I avoid it using void around it, then I set a variable with the scope personal with the name "example" and the executing user's id, and the content of it first looks whether the provided argument exists using the function "!?" which only dispenses true or false as strings, (if it dispenses them as boolean, I wouldn't even need comparator and 2nd statement) and if the user added arguments, then it is only the first argument that is set as the value of this variable, if there is no argument, then the variable value is the string "help"
Sidenote: the tag breaks if an argument at a specific position {args;0} is called and nothing returns, and it can't test for nothing.
My question was whether if can be used inside value.x = <here?>;
Last edited by ( . )( . ); Mar 21, 2022 @ 5:05pm
Gariam Mar 21, 2022 @ 3:19pm 
Originally posted by ( . )( . ):
I'd also like to know how I can add if()'s within the value defining code?
As the syntax is now, it tells me that this is not possible?
Do you meen having an if statement directly while assigning a value to a variable? If yes you can use this method:
variable = condition ? value if condition is true : value if condition is false

Something like this:
variable = engine.userProperties.dropdown == 0 ? true : false;

Edit: answer to you last question, depending on the language the usage of ='s might change but in all languages i've seen it's as Rhy told you... then, === is a strict equality (search this on internet for a more in depth explanation), meaning if the two arguments are exactly the same thing it returns true if not false... for example, 2 == '2' will return true because the both reppresent the same value of 2, while 2 === '2' will return false because one is a number the other is a string... and 3 is the max number of ='s
Last edited by Gariam; Mar 21, 2022 @ 3:39pm
Bruhsty Mar 22, 2022 @ 1:11am 
For things like combo properties you can also use switch()
( . )( . ) Mar 22, 2022 @ 5:11am 
But switch() listens to only one changeable state and also chooses only one entry to execute.
The code provided shows that I use 2 if()'s outside one another.
(like 2 horizontal wires and 2 vertical wires touching each other at 4 points)

Is it possible to change font and get the dimensions of the element?
< >
Showing 1-9 of 9 comments
Per page: 1530 50

Date Posted: Mar 21, 2022 @ 9:44am
Posts: 9