As stated on my profile, I'm a noob when it comes to Javascript with no real world experience. As I try to develop my game through scripting like adding mechanics and gimmicks, I noticed that I have so many If Statements running during a battle on its update function (meaning this if statements run every frame).
I didn't notice any lag during a battle as my old PC is probably enough to handle it (i3-8100 and GTX 1060). But my goal is to develop an rpg game for mobile first.
What I did to my functions is add another If Statement so that the function that will process my mechanics will only be run once. Here is an example:
The function processUpdateAction() is being run at every frame and the function updateAction() will only be run once, as long as indexAction has the same value.
I have like 15-20(not sure) of this if statements always checking conditions in every frame of the battle right now. No lag on my PC, but I still haven't test this on a mobile phone.
My question is, will a hundred of this if statements running on every frame impact the game's performance? How about thousands? I'm just worried about this as I still have many things to add. Thanks!
I didn't notice any lag during a battle as my old PC is probably enough to handle it (i3-8100 and GTX 1060). But my goal is to develop an rpg game for mobile first.
What I did to my functions is add another If Statement so that the function that will process my mechanics will only be run once. Here is an example:
JavaScript:
var dontRepeat_processUpdate = 100;
function processUpdateAction()
{
if(updateActionBoolean)
{
var indexAction = $gameActors.actor(actorID)._indexSomething;
if(dontRepeat_processUpdate != indexAction)
{
dontRepeat_processUpdate = indexAction;
updateAction(indexAction); //the process function
}
}
}
The function processUpdateAction() is being run at every frame and the function updateAction() will only be run once, as long as indexAction has the same value.
I have like 15-20(not sure) of this if statements always checking conditions in every frame of the battle right now. No lag on my PC, but I still haven't test this on a mobile phone.
My question is, will a hundred of this if statements running on every frame impact the game's performance? How about thousands? I'm just worried about this as I still have many things to add. Thanks!