If logic
Last updated
Last updated
If statement is a function that checks if the value meets the condition. If statements are based on Booleans (true & false). This is used literally everywhere, to tell your code what to do.
The above code specifies 3 variables velocity - players x position - and players y position
We have created a function that changes the velocity by one every time the player moves the in-game character, then creates a variable speed that adds the two variables player. x and the player's velocity which makes the player's movement less choppy.
Then we stated if velocity = 210 I want you to reset it because if we let velocity go up then the game will be unplayable
Just like the code snippet above this if statement asks if the value is = to a condition, in our case we have a message event that has an if statement, and asks if the value is = to the condition and if that is True then the bot shall respond with Peter Duh.
Word of advice please do not use statements more than 5 times in one command they can and will slow your bot down, but also slow down scratch for discord, so it is recommended that you use State Machines.
Else statements are simply a return, if the value is equal to condition, then do, else value is not equal to the condition return as false. Here is an example
An example of a else statement in Scratch For Discord
The first if statement validates if their message content is true, if it is then it further validates if their id is equal to the needed Id in order to run this command, If it is true then it returns Peter Duh, else it is not then it responds with Sorry you do not have access to this command.
Else if statements are the same but with further definition
Basically x = 1 and y = 0 if x is greater than y, print success message, else print x is too low.