Need help solving an eventing issue

I'm eventing an image based menu. The main menu works well, there;s no problem with it. However, there's a problem with the inventory.
I planned my menu like this:
Spoiler: screenshot
Capture3.PNG

When inventory icon is chosen, this common event is called:

Spoiler: screenshot
Capture4.PNG
The items are evented like this:
Spoiler: screenshot
Capture.PNG
Spoiler: screenshot
Capture2.PNG


When right mouse button is pressed, the inventory screen should close. (See above) So, the inventory screen (the background) should be removed. Also, I have to close the inventory, so I turned switch inventory check off. as a result, the image shouldn't be shown (the condition is if switch inventory check is off, see third picture) because the inventory is off.

However, when I go to playtest, this happens: (I choose inventory icon)
Spoiler: screenshot
upload_2019-6-4_22-45-1.png

the inventory shows up. But I don't wanna use it now, suppose. So I right click and the inventory closes.

Spoiler: screenshot
Capture6.PNG

Spoiler: screenshot
Capture7.PNG
But the image is still there -___- Isn't the picture NOT supposed to be there, since the switch is off? So many issues with this ughhhhh.

Also, I wwant the player to use right mouse button to open and also close the menu. If I open it however, using the same conditional branch as in the picture, it doesn't close anymore? What the heck is going on! I spent the whole afternoon doing this stuff. My head hurts and can't think

Please helppp *cries*



EDITTTT: Okay... I'm an idiot. A picture once shown remains unless it's erased.


So... I erased it in place of turning switch off. Now the image isnt shown at all after opening the 2nd time.
In your first screenshot, what plugin are those Plugin Commands from? Can you provide a link to that plugin?
Instead of using many switches could you not just erase all pictures on right mouse click?

As I understand it you activated (draw) the picture, then you disable the code to draw the picture with the switch but you never erase the picture, so it is still drawn from the first time the command is run.

You could use this script command inside the right mouse click event:

Code:
// Erase all Pictures
for (var i = 1; i <= 100; ++i) {
$gameScreen.erasePicture(i);
}

If you do not want to erase all the pictures because, lets say, picture IDs 1-5 are used for HUD elements and 70-100 for other stuff you could set var i = 6 and i <= 69. So it will start to erase pictures ongoing from ID 6 up to pictures with ID 69.
@Aloe Guvner I don't remember where I got it from. I'm away from my pc so I'll try to find the source or send it to you via message when I can use it again.

@XZINED I realized that a while ago. But now the problem is that if I remove the image, later on it should still be shown when the inventory is opened. But it's only there the first time. It's never shown after being erased.
I would highly advice that you simplify your inventory eventing. It looks to me that you use a parallel process for every item in the inventory, am I right?
That will cause your inventory to use a lot of computing power and it will be very vulnerable to bugs, like the one you have. And it is also more complicate for you to do.

You only need 1 common event, that is not parallel, for all the items that you will ever have in the inventory.

Inside you just need a couple of if checks.

If your game doesn't use the normal RPG Maker inventory I would suggest that you make one blank item in the Database for every item that you use in your game. Just with its name. The player will never see these but then you do not need hundreds of variables and switches. You could just use event commands to add or remove these items to and from the hidden inventory. To draw the items in your actual inventory you could use simple item checks:

If actor has item phone -> draw picture phone

And when closing the inventory just erase all pictures.
Yes, I did try doing it the easier way but, this is an image based menu. This inventory won't work the same way as a normal inventory. Because, the picture coordinates aren't fixed... I assigned 15 switches to 15 slots. If there's an item in slot 1, turn switch 1 off. Then no other item can be placed in that slot. This whole picture based thingy is the problem. If it were a normal menu, the engine could calculate where the image needs to be placed.

Here even if I use the if player has item, draw item condition, I would still a ton of switches to know where the picture shoyld be drawn. And also, after drawing, turn a switch on that it's drawn because I don't want it to be drawn in another slot. Because the phone will try to be in slot 1, if that's occupied, slot 2... if that's also occupied, slot 3, or slot 4...... so a switch should be turned on so that as soon as a slot... say, slot 3 is empty, it turns on so that the pucture isn't drawn is slots 4 and above, even if they're empty.

I tried really hard to make this easy, but oh well... didn't turn out great. I'll have a look at it tomortow again.
Maybe before starting to Code it, there should be made a detailed plan of what should happen when.
Also is this Menu supporting touch input on the pictures or only directional button input?

Edit: For the Itemslots, there should be a solution. Some Brainstorming.
- 1 Variable for each Item Slot, which contains current Item Id in that slot or zero for empty.
- 1 Picture Id with static Position for each Slot.
- When Menu Opens the show Picture Script Command can be made more flexible with script snippet and Item Slot Var Value can be used to determine correct Picture Graphic for Picture Id of this Slot also.
https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-mv-script-call-list.46456/
$gameScreen.showPicture(pictureId, name, origin, x, y,
scaleX, scaleY, opacity, blendMode)
If you name your Item Pictures 1 to 99, than you could use each Item Slot Variable for picture name 15times
and dynamicly show the correct picture for each single static item slot.

but this would be only the start... maybe it somehow helps with planing the item slots for your menu.
Here even if I use the if player has item, draw item condition, I would still a ton of switches to know where the picture shoyld be drawn. And also, after drawing, turn a switch on that it's drawn because I don't want it to be drawn in another slot.

Oh no, you do not need all of that. :LZSsmile:

You just need to sort the items in the database the way you want them to have slot priority in your inventory. For example, if your phone should always be #1 have it to be the first item in the database.

Then you will need a script command inside a common event that is not a parallel, nor an autorun process and it also doesn't need a switch. I assembled some code for you:

Code:
let max_items = 100; let picture_count = 2; let picture_width = 128; let picture_height = 64; let slot1_x = innerWidth/2-picture_width*3; let slot1_y = innerHeight/2-picture_height;
let item_count = 0; let slot_position = 0;
for (i=1; i<=max_items;i++) {
    if ($gameParty._items[i] > 0) {
        item_count += 1; slot_position += 1;
        if (slot_position >5) {let slot_position = 1;}
        switch (true) {
            case (item_count <6): $gameScreen.showPicture(item_count+picture_count , $dataItems[i].name, 1, slot1_x+picture_width*slot_position, slot1_y, 100, 100, 255, 0); break;
            case (item_count >5 && item_count <11): $gameScreen.showPicture(item_count+picture_count , $dataItems[i].name, 1, slot1_x+picture_width*slot_position, slot1_y+picture_height, 100, 100, 255, 0); break;
            case (item_count >10): $gameScreen.showPicture(item_count+picture_count , $dataItems[i].name, 1, slot1_x+picture_width*slot_position, slot1_y+picture_height*2, 100, 100, 255, 0); break;
}}}

This script will check the regular inventory (that we just use for the simplicity) if your party has some items. If there is an item in the inventory it will be drawn based on some positional parameters and its item name will be the image name in your game folder.

max_items is the maximum amount of items your game/database has. Change it to the number of your items.
picture_count is the number of other pictures that you draw, before you draw the inventory items. From what I have seen the inventory items will start with picture ID 3, because you draw 2 pictures before.
slot1_x is the x position of the very first inventory slot. The default value that I set is based on the assumption that the item in the middle should be drawn in the very center x position of the screen. Note: Due to how I set the code up this must be 1*picture_width smaller than the actual x position, if you change it.
slot1_y is the y position of the very first inventory slot. (And therefore the y position of the first inventory row.). I also set it to the center y position of the screen, altough it looks like you sat it a little more below that. You can change it to your needs.
picture_width is the pixel width of your item pictures.
picture_height is the pixel height of your item pictures.

You need to name the item pictures in your projects folder exactly like you name them in the item database for this to work. Example: Phone.png.

It may look complicated at first to you but it will make your life simpler. Just edit these few parameters in the first line and you will only need to ever use add/remove item and check item again.
It also has the benefit that your players may obtain the items through a shop or something.
I could not test this though, as I do not know the size of your inventory pictures, their positions and I am too lazy to set this all up. 😀
So I have absolutely no clue if this will work or if your computer will explode. 😂
(It will not explode)

Also consider: If you let players close the inventory only with the right mouse button, all players using touch devices, including notebooks, will have troubles doing so. You should use an icon instead (or additionally). That icon (and right mouse button) calls a common event to delete all drawn inventory icons.

Script command in that common event (not parallel, not auto, no switch):
Code:
$gameScreen.clearPictures();


You should also think about what will happen if the player finds a 16. or 17. item. Will there be pages in your inventory? Or only a total of 15 items that a player can find?


Cheers 👋
@XZINED Ooohhh I'll try this. Definitely seems better than using a ton of variables and switches and killing my brain. I did find out the issue with my setup though. I forgot to turn off a switch which was erasing the image.

Right click should work on android. It's a tap with two fingers... and I plan to keep my game on desktop only.

The protagonist has a small bag. I assume they can only take 15 itens. If more no new items will be added. They'll be informed that they can't take anymore items.

Also... I'd like it if the pictures can be drawn based on the order they are collectrd? If I find a chalk first, even if phone is the first in database, I want the chalk to show in slot 1. I shouldn't be so greedy though. It's already alot that u made that code for me. Thank you. But If it's alright with you, can you please look into this?

I'll try this one regardless and let you know. Hopefully If I run into any problems, you can help me. Thanks!
@XZINEDRight click should work on android. It's a tap with two fingers... and I plan to keep my game on desktop only.
Oh, good to know. 😀

Also... I'd like it if the pictures can be drawn based on the order they are collectrd? If I find a chalk first, even if phone is the first in database, I want the chalk to show in slot 1. I shouldn't be so greedy though. It's already alot that u made that code for me. Thank you. But If it's alright with you, can you please look into this?

I'll try this one regardless and let you know. Hopefully If I run into any problems, you can help me. Thanks!
Oh I see! I misunderstood you before. Yeah that way it makes a lot more sense. I will look into this and give you the updated code. :LZSsmile:

Hopefully If I run into any problems, you can help me. Thanks!
Sure 👋



Edit:
Okay so I tinkered around and I think the best solution, for having the right item order, might be to use an array for this.

The new code would be:
Code:
//You have to edit the values below (in the second line)
let picture_count = 2; let picture_width = 128; let picture_height = 64; let slot1_x = innerWidth/2-picture_width*3; let slot1_y = innerHeight/2-picture_height*2;

//Do not edit anything below this line, unless you know what you are doing :)
let slot_index = 0; let row_index = 1;
if ($inventory.length > 0) {
    for (i=1; i<=$inventory.length;i++) {
        slot_index += 1;
        if (slot_index >5) {let slot_index = 1; row_index += 1}
        $gameScreen.showPicture(i+picture_count, $inventory.toLowerCase(), 1, slot1_x+picture_width*slot_index, slot1_y+picture_height*slot_index, 100, 100, 255, 0); break;
    }
}

To add new items you have to use a script command now:
Code:
$inventory.push("phone")
Do not forget the " " before and after the word. It is best if you write all items fully in lower case only. It is to prevent upper or lower case mistakes breaking your inventory. You will no longer need to set up your items in the database. That would have been redundant, cause for this script commands are needed anyway.

To delete an item from the inventory:
Code:
let delete_item = "notebook"

//Do not edit anything below this line, unless you know what you are doing :)
if ($inventory.includes(delete_item.toLowerCase())) {$inventory.splice($inventory.indexOf(delete_item.toLowerCase()), 1);}

To check if the player has an item:
Code:
$inventory.includes("coffee")


You can use this one with a regular conditional branch too.

f8mlu.jpg



Or check the number of items in the inventory:
Code:
$inventory.length
ny8mz8.jpg



Important
On the very start of your game
you have to call this script command to initialize the inventory array:
Code:
$inventory = []


Let me know if that works for you. And if it had any problems. The Y coordinates, of the pictures drawn, will most likely be wrong. I didn't know the Y position of your first inventory slot.

Cheers 👋
I actually give up. This cannot be evented. I tried a lot. There are always problems here and there. So I moved to using a plugin and it fits my needs. Thanks to all who tried to help ^^
This thread can be closed now.
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/need-help-solving-an-eventing-issue.109700/