Hey guys,
It seems that labels arent an actual thing in javascript, so i tried to replicate it with a loop:
dont pay attention to the actual contents of the if statement - The bottomline is: the game checks if the first if statement passes, if it does it executes the code inside and it breaks the loop because it doesnt have to check further, if it doesnt it goes to the next if statement in line, and repeats the process, until it reaches the bottom and it breaks the loop.
My question is: is this even a good way to actually deal with this problem? and are there alternative more efficient methods?
Thanks in advance!
It seems that labels arent an actual thing in javascript, so i tried to replicate it with a loop:
Code:
for (var i = 0; i = 1;) {
if (G_dirpressed.search(/[1]/)>=0 && $gameMap.regionId($gamePlayer.x-1, $gamePlayer.y+1) !== G_cantpass) {if ($gamePlayer.canPassDiagonally($gamePlayer.x, $gamePlayer.y, 4, 2)) {dire = "4, 2"; break;}};
if (G_dirpressed.search(/[3]/)>=0 && $gameMap.regionId($gamePlayer.x+1, $gamePlayer.y+1) !== G_cantpass) {if ($gamePlayer.canPassDiagonally($gamePlayer.x, $gamePlayer.y, 6, 2)) {dire = "6, 2"; break;}};
if (G_dirpressed.search(/[7]/)>=0 && $gameMap.regionId($gamePlayer.x-1, $gamePlayer.y-1) !== G_cantpass) {if ($gamePlayer.canPassDiagonally($gamePlayer.x, $gamePlayer.y, 4, 8)) {dire = "4, 8"; break;}};
if (G_dirpressed.search(/[9]/)>=0 && $gameMap.regionId($gamePlayer.x+1, $gamePlayer.y-1) !== G_cantpass) {if ($gamePlayer.canPassDiagonally($gamePlayer.x, $gamePlayer.y, 6, 8)) {dire = "6, 8"; break;}};
if (G_dirpressed.search(/[2]/)>=0 && $gameMap.regionId($gamePlayer.x, $gamePlayer.y+1) !== G_cantpass) {if ($gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 2)) {dire = "2"; break;}};
if (G_dirpressed.search(/[4]/)>=0 && $gameMap.regionId($gamePlayer.x-1, $gamePlayer.y) !== G_cantpass) {if ($gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 4)) {dire = "4"; break;}};
if (G_dirpressed.search(/[6]/)>=0 && $gameMap.regionId($gamePlayer.x+1, $gamePlayer.y) !== G_cantpass) {if ($gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 6)) {dire = "6"; break;}};
if (G_dirpressed.search(/[8]/)>=0 && $gameMap.regionId($gamePlayer.x, $gamePlayer.y-1) !== G_cantpass) {if ($gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 8)) {dire = "8"; break;}};
if (G_dirpressed.length === 1) {$gamePlayer.setDirection(Number(G_dirpressed))}
break;
};
dont pay attention to the actual contents of the if statement - The bottomline is: the game checks if the first if statement passes, if it does it executes the code inside and it breaks the loop because it doesnt have to check further, if it doesnt it goes to the next if statement in line, and repeats the process, until it reaches the bottom and it breaks the loop.
My question is: is this even a good way to actually deal with this problem? and are there alternative more efficient methods?
Thanks in advance!