User Tools

Site Tools


item_pickup_tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
item_pickup_tutorial [2018/03/07 20:35] justinitem_pickup_tutorial [2018/03/07 20:51] justin
Line 1: Line 1:
 ======Item Pickups====== ======Item Pickups======
- 
-(WIP) 
- 
 This tutorial will explain how to set up map [[object|objects]] as [[item|items]] for the [[player_character|player]] to pick up, for example a key that the [[player_character|player]] can pick up by walking into/over it and then use to open a door or treasure chest. This tutorial will explain how to set up map [[object|objects]] as [[item|items]] for the [[player_character|player]] to pick up, for example a key that the [[player_character|player]] can pick up by walking into/over it and then use to open a door or treasure chest.
  
Line 8: Line 5:
  
 =====Creating the Object Model===== =====Creating the Object Model=====
- 
 Open the [[New Resource Dialog]] and create a new [[object]]. Once the [[Voxel Editor]] opens for the new [[object]] model, use the [[voxel]] tools to build a key as shown below (or whatever will best visually represent the [[item]]). Open the [[New Resource Dialog]] and create a new [[object]]. Once the [[Voxel Editor]] opens for the new [[object]] model, use the [[voxel]] tools to build a key as shown below (or whatever will best visually represent the [[item]]).
  
Line 27: Line 23:
  
 =====Creating a Sound Effect===== =====Creating a Sound Effect=====
-Optionally, you can create a [[sound|sound effect]] for the game to play when the [[item]] is picked up by the [[player_character|player]]. To do so, click the [[sound_fx_generator||Sound FX Generator]] button at the top, then click one of the presets along the left to find a [[sound]] that goes well with the [[item]]. In this example, the "Pickup/Coin" preset should work well.+Optionally, you can create a [[sound|sound effect]] for the game to play when the [[item]] is picked up by the [[player_character|player]]. To do so, click the [[Sound FX Generator]] button at the top, then click one of the presets along the left to find a [[sound]] that goes well with the [[item]]. In this example, the "Pickup/Coin" preset should work well.
  
 {{:wiki:item_pickup_tut_sfx.gif?nolink|}} {{:wiki:item_pickup_tut_sfx.gif?nolink|}}
Line 60: Line 56:
 set_entity_script(self, ""); set_entity_script(self, "");
 </code> </code>
 +
 +This line removes the [[script]] from the [[entity]] that activated it ("self"), in this case the [[tile]] that the [[player_character|player]] stepped onto. This is to prevent the [[script]] from being activated more than once after it's triggered the first time. The pair of double quotes (i.e. an empty [[string]]) indicates that the [[script]] should be removed/set to nothing.
  
 <code lua> <code lua>
 remove_entity(entity["key_01"]); remove_entity(entity["key_01"]);
 </code> </code>
 +
 +This line removes the physical key [[object]] from the scene by referring to the unique [[entity]] ID we assigned to the key earlier on in the [[Map Editor]]. The ID inside the quotes should exactly match the ID that was assigned to the [[object]] earlier on from its [[Entity Properties]] dialog.
  
 <code lua> <code lua>
 play_sound("give_key"); play_sound("give_key");
 </code> </code>
 +
 +This line plays the [[sound|sound effect]] named "give_key". The name inside the quotes should exactly match the name given to the [[sound]] when it was saved from the [[Sound FX Generator]]. To prevent any errors, this line should be deleted from the [[script]] if you skipped the optional step of creating a [[sound|sound effect]].
  
 <code lua> <code lua>
Line 73: Line 75:
 </code> </code>
  
-Note that this line doesn't have a semicolon at the end since semicolons are used as line separators in the RPG in a Box scripting language and this is the last line of code.+This line puts the [[item]] named "Gold Key" into the [[player_character|player's]] [[inventory]]. The name inside the quotes should exactly match the name defined in the [[Item Editor]]. Note that this line doesn't have a semicolon at the end since semicolons are used as line separators in the RPG in a Box scripting language and this is the last line of code.
  
-=====Testing the Pickup In-Game=====+Click the "Validate" button and then OK once the [[script]] has been validated, then save the [[map]].
  
-Finished! Save map and export gameplayer will now "pick up" key when walking onto the tile.+=====Testing the Pickup In-Game===== 
 +[[exporting_your_game|Export the game]] to try out your new [[item]] pickup. The [[player_character|player]] should now receive a Gold Key in their [[inventory]] when walking onto the [[tile]] that contains the key [[object]]!
  
 {{:wiki:item_pickup_tut_ingame.gif?nolink|}} {{:wiki:item_pickup_tut_ingame.gif?nolink|}}
  
item_pickup_tutorial.txt · Last modified: 2018/03/07 20:58 by justin