Image:
 Author: AverageCoder Group: Default Filesize: 1.04 MB Date added: 2024-06-14 Rating: 5 Downloads: 1337 Views: 208 Comments: 0 Ratings: 1 Times favored: 0 Made with: Algodoo v2.2.0b Tags:
|
If you are on mobile, go away
If you are on pc, stay
If you are a advanced coder or you just want to understand how it works, you can look at the code and see how it functions
postStep snippet:
(e)=>{
anims := [_left, _down, _up, _right];
animsOffsets := [_leftOffsets, _downOffsets, _upOffsets, _rightOffsets]; <-- This line and the one above defines what animations and offsets will be used in the form of a list
waitTime := 0.4; <-- how long in seconds it takes for the animation to go back to idle
framerate := 12; <-- frames per second
keys.isdown("shift") && Keys.isDown("z") ? {
_intendedPos = app.mousePos
} : {};
_gamePlayMode ? { <-- If the _gamePlayMode variable is true, then execute everything in the first set of {} brackets
_playAnimOnce(anims(_currentAnimation), 12, animsOffsets(_currentAnimation), _timeWhen, sim.time);
Keys.isDown(_keybinds(0)) ? { <-- If the key that is down matches _keybinds(0) in which keybinds is the list [c,v,n,m], do the stuff in the first set of brackets
_1 ? {
_1 = false;
_timeWhen = sim.time;
_currentAnimation = 0
} : {};
_timeWhenLetgo = sim.time
} : {
_1 = true
};
} : {}
}
Lists can be very useful for things like this that would otherwise be too long
[1,0](_var)
instead of :
_var == 1 ? 1 : 0
both would return 1 if _var is equal to 1 and 0 if _var is not equal to 1
with larger if statements it can get very cluttered
The way that it works is that the number in the () brackets returns what correlates with it in the [] brackets
for example : [1,2](0) returns 1, [32,45,63](2) returns 63, [1](0) returns 1
The way that it is used for the post step code is very useful, I will use it for future projects
the [_left,_down,_up_right] are also all lists, and when one of them are chosen, it returns the list that the variable went to so I wouldnt have to code every one of them seperate for the _playAnimOnce code
speaking of it, it is a function
basic function code would be like
(variableIdk)=>{_idk = variableIdk}
this makes it so you could write something like :
_absolute := (number)=>{number >0 ? number * 1 : number * (-1)}
it would return the absolue value of the number inputted that would then always be positive
for example : _absolute(-1) returns 1 and _absolute(2) returns 2
I hope this helps people in the communtiry understand how Thyme code works |