07-25-2017, 01:02 PM
(This post was last modified: 07-25-2017, 01:34 PM by Filler.
Edit Reason: Had to disable smilies.
)
That's true.
Most of it can be massively cut down, though.
For example, instead of having a massive hierarchy of if/otherwise statements for player movement. I could do a single, simple if statement that checks if any of the movement keys were pressed, and applies X/Y speed based off variables. Below the script could be 2 if/otherwise if statements that change the X/Y speed off what keys were held down. It's far more shorter in terms of code than the method I have right now, and less checks are involved.
For example, my original movement code was 700-something lines long (Judge me for being a bad coder, please). While this new one is far smaller.
/* ======================== When Updating ========================= */
addWhenUpdatedListener(null, function(elapsedTime:Float, list:Array<Dynamic>):Void
{
if(wrapper.enabled)
{
if((isKeyDown("right") || (isKeyDown("left") || (isKeyDown("down") || isKeyDown("up")))))
{
if(isKeyDown("up"))
{
_Yspeed = asNumber(-10);
propertyChanged("_Yspeed", _Yspeed);
}
else if(isKeyDown("down"))
{
_Yspeed = asNumber(10);
propertyChanged("_Yspeed", _Yspeed);
}
if(isKeyDown("right"))
{
_Xspeed = asNumber(10);
propertyChanged("_Xspeed", _Xspeed);
}
else if(isKeyDown("left"))
{
_Xspeed = asNumber(-10);
propertyChanged("_Xspeed", _Xspeed);
}
actor.setXVelocity(_Xspeed);
actor.setXVelocity(_Yspeed);
}
else
{
actor.setXVelocity(0);
actor.setXVelocity(0);
}
}
});
}
override public function forwardMessage(msg:String)
{
}
}
It's neat, and clean. And if you're wondering what it looks like in visual code mode, it's just as clean.
EDIT: This script could be even further optimized by running it so that it detects only when keys are pressed, instead of using an always updating script.
While it looks longer, it'll use less memory as it doesn't check every frame. This doesn't support cornered movement, yet.
Most of it can be massively cut down, though.
For example, instead of having a massive hierarchy of if/otherwise statements for player movement. I could do a single, simple if statement that checks if any of the movement keys were pressed, and applies X/Y speed based off variables. Below the script could be 2 if/otherwise if statements that change the X/Y speed off what keys were held down. It's far more shorter in terms of code than the method I have right now, and less checks are involved.
For example, my original movement code was 700-something lines long (Judge me for being a bad coder, please). While this new one is far smaller.
/* ======================== When Updating ========================= */
addWhenUpdatedListener(null, function(elapsedTime:Float, list:Array<Dynamic>):Void
{
if(wrapper.enabled)
{
if((isKeyDown("right") || (isKeyDown("left") || (isKeyDown("down") || isKeyDown("up")))))
{
if(isKeyDown("up"))
{
_Yspeed = asNumber(-10);
propertyChanged("_Yspeed", _Yspeed);
}
else if(isKeyDown("down"))
{
_Yspeed = asNumber(10);
propertyChanged("_Yspeed", _Yspeed);
}
if(isKeyDown("right"))
{
_Xspeed = asNumber(10);
propertyChanged("_Xspeed", _Xspeed);
}
else if(isKeyDown("left"))
{
_Xspeed = asNumber(-10);
propertyChanged("_Xspeed", _Xspeed);
}
actor.setXVelocity(_Xspeed);
actor.setXVelocity(_Yspeed);
}
else
{
actor.setXVelocity(0);
actor.setXVelocity(0);
}
}
});
}
override public function forwardMessage(msg:String)
{
}
}
It's neat, and clean. And if you're wondering what it looks like in visual code mode, it's just as clean.
EDIT: This script could be even further optimized by running it so that it detects only when keys are pressed, instead of using an always updating script.
While it looks longer, it'll use less memory as it doesn't check every frame. This doesn't support cornered movement, yet.