Adding A Boolean

I am completely new at coding, and I'm trying to add a Boolean to my text(if necessary, or another means of coding). The problem I'm having is that I'm not sure how to do so, and the other tutorials on Quest, although helpful, didn't help me understand what I'm doing wrong. Here is what I'm trying to do:

I want the character to to have a randomly decided amount of coins, and have a choice to buy something, but can't if they don't have enough.

I am completely lost on how to do so.


(filler for getting my edited post, updated/posted)


you don't need a Boolean Attribute for any thing of what you want to do, but you do need an Integer Attribute for the coins and the price for your item/equipment that you want to buy/sell

in code, an example:

<game name="example_game">

  <attr name="start" type="script">

    player.coins = GetRandomInt (50,100) // initial random starting amount of coins (50 to 100)

  </attr>

</game>

<object name="room">

  <inherit name="editor_room" />

</object>

<object name="player">

  <inherit name="editor_object" />
  <inherit name="editor_player" />

  <attr name="parent" type="object">room</attr>

  <attr name="coins" type="int">0</attr>

</object>

<object name="sword">

  <inherit name="editor_object" />

  <attr name="parent" type="object">room</attr>

  <attr name="price" type="int">75</attr>

  <displayverbs type="stringlist">

    <value>buy</value>

  </displayverbs>

  <inventoryverbs type="stringlist">

    <value>sell</value>

  </inventoryverbs>

  <attr name="buy" type="script">

    <![CDATA[

      if (player.coins >= sword.price) {
        player.coins = player.coins - sword.price
        sword.parent = player
        msg ("You buy the sword")
      } else {
        msg ("You don't have enough to buy the sword")
      }

    ]]>

  </attr>

  <attr name="sell" type="script">

    player.coins = player.coins + (sword.price / 2)
    sword.parent = room
    msg ("You sell your sword")

  </attr>

</object>

<verb>

  <property>buy</property>
  <pattern>buy</pattern>
  <defaultexpression>You can't buy that!</defaultexpression>

</verb>

<verb>

  <property>sell</property>
  <pattern>sell</pattern>
  <defaultexpression>You can't sell that!</defaultexpression>

</verb>

to do the same as the code example above, within the GUI/Editor:

left side's "tree of stuff" for a default new game:

(it might be slightly off and/or missing some stuff... as I'm just going on memory, as I don't have quest GUI/Editor open at the moment)

Objects
-> 'game' Object (this is a special and required Object, that holds game-wide settings/attributes/controls/options and also holds the publishing info, that is shown/displayed on the quest servers/online, as string attributes, and the special 'start' script attribute, which is the very first thing that is done/run/executed/activated when your game begins, making it good for doing character creation, setting the values, especially random values, for your initial stats/attributes, and/or a game introduction, for examples)
->-> Verbs
->-> Commands
-> 'room' default new game Room Object
->-> 'player' default new game Player Object
Functions
Timers
Walkthrough
Advanced
-> 'english.aslx' language game engine library file
-> 'core.aslx' hub (links/references to all the 'core' library files) library file of the core game engine library files
-> Object Types
-> Javascript
.
.
.
.
.
.
.
Filter -> Show Library Elements -> checked (toggled on) / unchecked (toggled off) // this shows/hides all of the built-in functionality within the tree of stuff above, as light grey text (if toggled on / checked in)

'game' Object -> 'scripts' Tab -> 'start' Script -> (see below)

add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable player.coins = [EXPRESSION] GetRandomInt (50,100)

'player' Player Object -> 'attributes' Tab -> 'Attributes' box (box at the bottom) -> Add -> (see below)

(Object Name: player)
Attribute Name: coins
Attribute Type: int // integer
Attribute Value: 0

'room' Room Object -> 'Objects' Tab -> Add -> (see below)

Object Name: sword

'sword' Object -> 'Verbs' Tab -> Add -> Verb Name: buy

'sword' Object -> 'Verbs' Tab -> Add -> Verb Name: sell

'sword' Object -> 'Attributes' Tab -> 'Attributes' box (at the bottom) -> Add -> (see below)

(Object Name: sword)
Attribute Name: price
Attribute Type: int // integer
Attribute Value: 75

'sword' Object -> 'Attributes' Tab -> 'Attributes' box (at the bottom) -> find and click on 'buy' so it is highlighted -> (see below)

add new script -> 'scripts' section/category -> 'if' Script -> (see below)

if [EXPRESSION] player.coins >= sword.price

-> then -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable player.coins = [EXPRESSION] player.coins - sword.price

-> then -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable sword.parent = [EXPRESSION] player

-> then -> add new script -> 'output' section/category -> 'print a message' Script -> (see below)

print [MESSAGE] You buy the sword

else -> add new script -> 'output' section/category -> 'print a message' Script -> (see below)

print [MESSAGE] "You don't have enough coins to buy the sword"

'sword' Object -> 'Attributes' Tab -> 'Attributes' box (at the bottom) -> find and click on 'sell' so it is highlighted -> (see below)

add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable player.coins = [EXPRESSION] player.coins + (sword.price / 2)

add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable sword.parent = [EXPRESSION] room

add new script -> 'output' section/category -> 'print a message' Script -> (see below)

print [MESSAGE] You sell your sword

'sword' Object -> 'Attributes' Tab -> 'Attributes' box (at the bottom) -> Add -> (see below)

(Object Name: sword)
Attribute Name: displayverbs
Attribute Type: stringlist
Attribute Value: (see below)

// hopefully it's something like this (hopefully you can figure it out, as I don't have the quest GUI/Editor open at the moment):

Add Item/Value -> buy

'sword' Object -> 'Attributes' Tab -> 'Attributes' box (at the bottom) -> Add -> (see below)

(Object Name: sword)
Attribute Name: inventoryverbs
Attribute Type: stringlist
Attribute Value: (see below)

// hopefully it's something like this (hopefully you can figure it out, as I don't have the quest GUI/Editor open at the moment):

Add Item/Value -> sell


let me know if you need anything or need help with anything... or if I'm missing something... or if something isn't working


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums