Ultimate Simple script guide

From Platinum Arts Sandbox Free 3D Game Maker
Revision as of 18:57, 19 October 2010 by Chocolatepie33 (Talk | contribs)

Jump to: navigation, search

Created by Chocolatepie33 (aka CP) with assistance from Kentl, made for 2.5 (2.6 changes will be added later)

  • Adding a level trigger
    • Open up Sandbox
    • Select a spot to add a talking character (via F1)
    • Next to the character, select a spot, then use ` (above TAB) to start the console. Type "newent mapmodel -1."
    • Select the surrounding box and hit F3. Go to level_trigger and use the slider to pick a number. Remember it. Also, while the menu is still up, go to trigger type and select either 8 (for repeated pop-up text) or 12 (one-time).
    • Move the box "into" the character.
    • Save your map.
  • Beginning scripting
    • Re-open the map you saved. Go into edit mode (E) and then hit F6. Go to the bottom of the menu and hit "Load", then "Execute".
    • You can also do this externally, outside of Sandbox: go to the Sandbox folder, then mystuff/packages/base. Either create a new .txt doc (make sure to save it as a .cfg) and edit it, or edit an existing one.
  • Scripting
    • A pop-up menu is known as a gui. Anything modifying the gui would use the -gui or gui- keywords (with the proper beginning or ending respectively).
    • Let's make a character named Jon say Hello and ask you how you're doing with options:
    level_trigger_1 = [showgui Jon] 
    newgui Jon [
      guitext "Hello, I'm Jon. How are you?" 
      guibar 
      guibutton "Fine, thank you." [echo "OK then."] 
      guibutton "Not well. Goodbye." [cleargui] 

]

  • Let's go over this code:
    • showgui Jon opens up the menu named Jon
    • newgui Jon creates a newgui, titled Jon, and the [] after the command "hold" the items within it.
    • guitext puts out the text specified within the "".
    • guibar creates a horizontal bar.
    • guibutton creates a selectable button, with a title within the "" marks. [] hold the commands that are executed when the button is selected. The echo command puts out text at the upper-left corner of the screen in Sandbox.
    • cleargui closes a gui, either permanently or until the NPC is approached again (trigger 12 or 8 respectively).
  • Adding inventory
    • Inventory and shop scripts are important to every game. Here's how to make'em:
    on_start = [
      item1 = 0
      item2 = 0
      money = 5000
      cake = 0
      pie = 0
      treasure = 0
    ]
    
    level_trigger_1 = [ item1 = ( + $item1 1 ) ]
    level_trigger_2 = [showgui npc1-1]
    newgui npc1-1 [
      guitext "Hello, what would you like to buy?"
      guibar
      guistayopen [
      guibutton "Cake: 5 dollars"  [ 
         if ( => $money 5 ) [ 
           cake = ( + $cake 1 )  
           money = ( - $money 5 ) 
           echo "You got a cake." ]
         if ( < $money 5 ) [ echo "Not enough money. Too bad." ]
         ]
      guibutton "Pie: 10 dollars" [ 
         if ( => $money 10 ) [ 
           pie = ( + $pie 1 ) 
           money = ( - $money 10 ) 
           echo "You got a pie." ]
         if ( < $money 10 ) [ echo "Not enough money. Too bad." ]
         ]
      guibutton "Treasure: 900 dollars"  [ 
         if ( => $money 900 ) [ 
           treasure = ( + $treasure 1 ) 
           money = ( - $money 900 ) 
           echo "You got a treasure."]
         if ( < $money 900 ) [ echo "Not enough money. Too bad." ]
         ]
         ] // end of guistayopen
      guibutton "No thanks. Goodbye." [cleargui]
         ] "Shopkeeper"
  • This is a long script, so let's go over it carefully:
    • on_start and its [] contain values to be created when the map starts. These are inventory items.
    • level_trigger_1 = [ item1 = ( + $item1 1 ) ] is the code used to add a quantity of an item.
    • npc1-1 is a trick used to create guis with the same title. We'll talk about it later.
    • guistayopen is a command used to keep a gui open when guibuttons are selected. Normally a guibutton would close a gui when selected, but the command prevents this. It only applies to guibuttons within it's [].
    • if ( => $money 5 ) is an if statement. An if statement checks to see if something is true. This if statement checks to see if you have at least (so the amount or more) 5 moneys. You start the map with 5000 moneys, so this statement is true. The [] afterwards hold commands to execute if the statement is true. For example, the cake you buy is added to your inventory because you have enough money to buy it.
    • ] "Shopkeeper" is part of the npc1-1 trick. It renames npc1-1 as Shopkeeper. If you create a gui with multiple pop-up windows, such as choosing a guibutton and having a new window pop up, the second window would be npc1-2, and it'd be renamed Shopkeeper by this trick.
  • Now, you might wanna know how to have a gui shown in the game. This code adds an inventory option to the main menu, which is accessed with the ESC button.
    newgui Inventory [
    guibutton "Back" [cleargui]
    guibar
    guitext ( format "You have %1 item1s." $item1 )
    // add more items here in above format
    ]
    newgui main [
      guilist [ 
         guilist [
            guibutton "Inventory" [showgui Inventory]
                 ]
              ]
            guibar
            @main
            ]
  • This code introduces some new and useful things:
    • guitext with ( format ... ): use this code to show how many items you have. The %1 character is replaced by the number of an item you have.
    • guilist is used to create a list within a gui.

Please go to part 2 here: