Javascript check two parameters to accept the entrance.

Hello,

I’m stuck on javascript programming for my rpg game.

I want my characters to have an access to a place if they have enough money to pay 5 credits and have with them the item « entrance ticket ».

I tried to create a script to have everything working :



if ($gameParty._gold < 5 ){

$gameMessage.add("You don’t have enough money");



} else {

$gameMessage.add("you have enough money");

$gameParty._gold = $gameParty._gold - 5;

$gameParty.gainItem($dataItems[5], 1);



}

But I don’t know how to check if the item is truly in stock because it doesn’t show in the inventory of my characters. However I can open the entrance gate which means (I guess )that the item is reknown (I changed the number of dataItems to test and the gate doesn’t open)



And I also tried with Rpg maker system, this time the ticket is properly shown in the inventory of my characters. Everything is working, except that I would like the seller to stop selling ticket when my character have already bought one and show them a message like : « You already have a ticket ».

javascript-rpg-maker-window.png


To recap I would like to do that :

-check if the character have enough money (5 credits)

-inform them if they don’t have enough credits

-inform them that they can’t buy other ticket if the already have bought one.



Thank you 🙂

Have a good day



Bap
ecause it doesn’t show in the inventory of my characters.
it does, just not in the conditional branch command - you need the control variable command.
the game data section (the one that defaults to map id) contains everything you want.
just use control variable to load the number you want into a variable (for example the number of tickets in inventory) and then check that variable with conditional branch
Not sure if I'm eventually getting something wrong here. But it looks like you can do the whole process without any actual javascript just by eventing properly.
You can do something along those lines:
ticket.PNG

On page 4 of the conditional branch you can check if the party has a ticket or not. The rest is simple branching.
@Andar and @Mewgles thank you very much for your answer, it works perfectly now 🙂
To recap I would like to do that :

-check if the character have enough money (5 credits)

-inform them if they don’t have enough credits

-inform them that they can’t buy other ticket if the already have bought one.
1596985122755.png
@ct_bolt thank you for your answer, do you know if there is a good "lexicon" to have a look at all the javascript "wording" for rpg maker when we use the script mode ?
@ct_bolt thank you for your answer, do you know if there is a good "lexicon" to have a look at all the javascript "wording" for rpg maker when we use the script mode ?
no prob.
There is but I still find it incomplete and sometimes not accurate:
Google Doc Spreadsheet: Click Here to View
Spoiler: Google Doc Spreadsheet

I usually just open up the javascript files in notepad++ and check the objects/functions.

For Example:
Spoiler
1596986662862.png

The highlighted line would be $gameParty.leader()
That would return the party leader information

Notepad++ also can show all functions in one very helpful window (aka. Function List):
Spoiler
1596986915107.png
@ct_bolt Waw ! top 🙂 thank you :LZSgrin:
@ct_bolt Waw ! top 🙂 thank you :LZSgrin:
No prob. Happy to help out a fellow game creator. ☺️ 👍
Happy Game Making! :popcorn:

Original thread: https://forums.rpgmakerweb.com/threads/javascript-check-two-parameters-to-accept-the-entrance.125077/