Help me figure out what's wrong with this event [solved]

Hyouryuu-Na

Currently Inactive
Veteran
Joined
Jun 15, 2017
Messages
419
Reaction score
868
First Language
Bangla/Bengali
Primarily Uses
RMMV
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:
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?
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,343
Reaction score
564
First Language
Italian
Primarily Uses
RMVXA
Does this always need to be in parallel process?
It does not, but when you use an item you are in the Menu scene, not in the Map scene. I am not sure what you get when using
Code:
$gameMap._events[X]
and I am pretty sure that no message can be displayed in the menu scene.

What you could do is to have the common event trigger a switch and go back to the map scene. Then you can turn the said switch off at the end of your event. This will ensure that the event runs in the Map scene.
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,683
Reaction score
451
First Language
English
Primarily Uses
N/A
How is the common event being run? Is it through the key?
 

Hyouryuu-Na

Currently Inactive
Veteran
Joined
Jun 15, 2017
Messages
419
Reaction score
868
First Language
Bangla/Bengali
Primarily Uses
RMMV
@Heirukichi Ah makes sense :0 I was using the select item command. But aside from show message, aren't the self switches going to turn off or on? Those should work right? Ok I have no idea TT But my game is bloating with so many switches and variables I wanted to lower their use a little.
@Oddball Yes

Edit: I figured out the problem. My event setting is correct. Now I've checked from the normal menu, not the select item menu. works fine now. Must have been an issue with some other plugin idk -_- or maybe I'm just stupid. Never fiddled around with items a lot before

Edit Edit: Hmm so, select item doesn't actually use items :/ ...Why am I so stupid -_-
 
Last edited:

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
1,893
Reaction score
893
First Language
Spanish
Primarily Uses
RMVXA
turn it around.
instead of watching the key, watch the door, and make the door go look for the key.
you *can* create a distance check right there on the event door, which takes that line out of your code, and run the validation on the door's code, which takes care of the rest.

common events should be used for .... well.... *common* things that have to be ran across multiple maps that can't possibly interact with one another.
if your event only takes care of that one door, then place the code at the door proper, and have it handle the sequence.

(And, script calls should only be used to handle things that can't possibly be handled via the in-editor blocks. Everything you coded there, is already coded in the default blocks, no need to code it again. You're doubling the work load!)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Can't wait for the next Sonichu
Birdhouses are usually made of wood. Birds typically live in trees. Trees are wood. Birdhouses are made of birdhouses.
He just discovered cellphones...

(I don't know why am I drawing so much these days...)
In medieval times, a common way to eat food was upon edible plates, which were made of bread, called trenchers.

Forum statistics

Threads
93,668
Messages
914,416
Members
123,254
Latest member
Ragnamano
Top