#author("2026-06-18T08:01:13+09:00","default:admin","admin") #author("2026-06-18T08:02:39+09:00","default:admin","admin") ''[[Beginner Tutorial INDEX:https://rpgbakin.com/pukiwiki_en/?RPG+Developer+Bakin+Beginner+Tutorial]]>>'' *Use variables [#e808a596] ''Let’s build a map where the player jumps to reach treasure chests placed in high locations, collects items, and progresses toward the boss room.'' ''Jumping adds a fun mechanic to your game, but it also introduces complexity to the design.'' ''In this tutorial, we’ll create a puzzle where opening five treasure chests inside a cave triggers a mechanism that opens a locked door leading to the boss room.'' **Building the Cave Map [#g70f71de] ''Modify the cave interior map you added earlier in the [[Map List Palette]] to match the image below.'' ''There are four key points:'' 1) Raise the outer edges by four layers (increase the Y coordinate by "1"). 2) Leave a 3-tile section on the back wall of the cave unraised. 3) In the unraised area, place "Labyrinth Wall" from [[Stamps Palette]] > Objects tab > reserved > Event Template. 4) Create five elevated platforms (2x2 tiles in size, 4 layers high) scattered across the map. Place "treasure chests" from [[Stamps Palette]] > Objects tab > reserved > Event Template on top of the raised platforms from step 4. We'll use variables to create treasure chests with randomly changing contents. #ref(./Use variables_1.jpg,40%) #br **Variables [#i8a1ec0d] ''Variables are an essential concept in game creation and are used frequently.'' You can think of a variable as a “box”—a named container that can hold values like numbers or text. By referencing the name of the "box" throughout your game, you can retrieve or change the data stored inside it. ''Note:'' Storing a value in a variable is called an ''&size(18){"assignment."};'' ***Creating a Variable [#y263c138] ''Let’s start by creating a variable to keep track of how many treasure chests have been opened.'' Open the [[Variable List]] from the master menu on the left side of the Map Editor. Under the Normal tab, click the Add button to create a new variable. Click the variable name to rename it to ''“Number of Opened Chests.”'' #ref(./Use variables_2.jpg,40%) #br ''And that’s it — your first variable is now ready!'' ''&size(16){And that’s it — your first variable is now ready!};'' ***Treasure Chests With Random Contents [#x0c4bbfc] ''Now let’s create the treasure chest itself.'' ''First, select one of the raised platforms and press G to open the Event Editor.'' Set the event name to “Random Treasure Chest” and the sheet name to “Examine Chest.” For the event graphic, choose a treasure chest from the reserved folder in the 3D Stamps, and set the motion to "close_keep." Set the Orientation Control to “Fixed.” #ref(./Use variables_3.jpg,40%) #br The event flow will go like this: ''&size(16){Open Chest Animation → Assign Random Number to a Variable → Check Variable → Give Item Based on Result};'' ''1. Leave the event trigger as “When Player Talks.”'' ''2. Add the “Sounds” category > “Play Sound Effect” panel, click “Sound Effects,” and select “SE_Treasure_Open_01” from the Asset Picker under SE > reserved > SE > Event Templates.'' ''3. From the Event category, add a Change Event Graphic panel. Select a treasure chest Open motion from the reserved folder under 3D Stamps.'' This completes the chest opening animation. ''4. From the Variable Box category, add an Advanced Variable Box Operation panel.'' Click on "What". In the Select Variable Box dialog, go to the Local tab and click the Add button. Rename "Local0" to "Random Value." In the "To What" field, set a random number with Min: 0 and Max: 2. For "Do what?", select Assign. This will assign a random value — 0, 1, or 2 — to the variable Random Value. #ref(./Use variables_4.jpg,40%) #br ''5. Add the “Multi-branch (by Variable Value)” panel from the “Conditional Judgment” category.'' Set “Random Value” as the “Variable Box Number.” Press the add button inside the panel to create “Condition Value 2” and “Condition Value 3.” Set “Condition Value 1” to "0", “Condition Value 2” to "1", and “Condition Value 3” to "2" respectively. You have now created branches that change according to the value of “Random Value”, which ranges from "0 to 2". #ref(./Use variables_5.jpg,40%) #br ''6.Set the items that can be obtained for each of the three branches determined by the “random value.”'' First, add the “Status” category > “Increase/Decrease Item” panel to the branch where the “Random Value” is “0”. Set Item to Medicinal Herb and Quantity to 1. This means that when Random Value = 0, the player receives a Medicinal Herb. ''7. Below the Increase/Decrease Item panel, add three more panels for item acquisition effects:'' From the Control category, add a Wait Specified Time panel and set it to 2 seconds. From the Sounds category, add a Play Sound Effect panel and set it to SE_Decide_01. From the Conversation category, add a Display Message panel and enter: "You received a Medicinal Herb!" #ref(./Use variables_6.jpg,40%) #br ''8. Set up the same flow for when Random Value = 1 and 2.'' For 1, set the item to Potion. For 2, set the item to Full Potion. #ref(./Use variables_7.jpg,40%) #br ''9. Since the player received an item, update the variable Number of Opened Chests to reflect that.'' Below the End Branching, add a Variable Box Assignment and Calculation panel from the Variable Box category. Set it to add 1 to the Number of Opened Chests variable. #ref(./Use variables_8.jpg,40%) #br ''10. Finally, we want to mark this treasure chest as "opened." Set an event switch and create a second event sheet to show the opened state.'' Refer to the page [Creating Events ①] for more details. From the Switch category, add a Event Switch ON/OFF panel From the Local tab, create a new event switch called "Opened" and turn it ON #ref(./Use variables_9.jpg,40%) #br ''11. Add a new event sheet, name it "Opened", and set the condition to "Opened switch is ON"'' #ref(./Use variables_10.jpg,40%) #br ''And that’s it! You’ve now created a treasure chest with randomly changing contents.'' ''&size(16){And that’s it! You’ve now created a treasure chest with randomly changing contents.};'' ***Placing the Treasure Chests [#h9bcdb28] ''Now that you’ve created the treasure chest, select it in the Map Editor, press Ctrl+C to copy it, and paste it onto the remaining four raised platforms.'' #ref(./Use variables_11.jpg,40%) #br ---- ''Using variables and branches based on their values is a powerful technique used in many game systems.'' ''In this tutorial, we used a random number, but you can also assign other types of values — like a character’s status or a password — to variables and use them in similar ways.'' ''There are several types of variables, each with different uses. Check out the [Variables] page for more details and try experimenting with various applications!'' ''Since the treasure chests are placed on elevated platforms, players won’t be able to reach them just yet.'' ''Next, let’s add a jump mechanic so they can access those high spots!'' ---- ''&size(16){Next: [[Jumping:https://rpgbakin.com/pukiwiki_en/?Jumping+%28Beginner+Tutorial%29]]};'' ''&size(16){Previous: [[Debug Features:https://rpgbakin.com/pukiwiki_en/?Debug+Features+%28Beginner+Tutorial%29]]};'' ---- ''[[Beginner Tutorial INDEX:https://rpgbakin.com/pukiwiki_en/?RPG+Developer+Bakin+Beginner+Tutorial]]>>''