So, instead of using a ton of switches and variables like I normally do to check if the player used the right item, I decided to use code. Smaller and more efficient... that's what I thought.
First, I put the code in a parallel event to see if it works. After I saw it does, I thought, why not use it in a common event and run it only once when the player uses the item? That would cause less lag. But surprisingly, it didn't work. Even though I just copy pasted from the parallel event that was working.
Here's the script:
Here, the event 19 is a door which I'm supposed to open with a key having the item id of 14. The variable id of selected item is 24. So when I select the right key, it's going to be removed and the door will open. That's all.
But why isn't it working from the common event in the item's effects?Does this always need to be in parallel process?
First, I put the code in a parallel event to see if it works. After I saw it does, I thought, why not use it in a common event and run it only once when the player uses the item? That would cause less lag. But surprisingly, it didn't work. Even though I just copy pasted from the parallel event that was working.
Here's the script:
Code:
var get_distance = [Math.abs($gamePlayer._x - $gameMap._events[19]._x), Math.abs($gamePlayer._y - $gameMap._events[19]._y)];
if (get_distance[0]<=1 && get_distance[1]<=1){
if ($gameVariables.value(24)==14){
$gameMessage.add("Used nickel key");
$gameParty.loseItem($dataItems[14], 1);
$gameSelfSwitches.setValue([7, 19, 'A'], true);
}
}
Here, the event 19 is a door which I'm supposed to open with a key having the item id of 14. The variable id of selected item is 24. So when I select the right key, it's going to be removed and the door will open. That's all.
But why isn't it working from the common event in the item's effects?Does this always need to be in parallel process?