Need some coding help with character creation

So I am working on setting up the player character and I get to choosing my race and I get an error. I will be posting my code down below to take a look at but for now I can't seem to figure out what the problem is.

msg ("Let's generate a character...")
msg ("First, what is your name?")
get input {
  player.alias = result
  msg ("Hi, "+ player.alias)
  ShowMenu ("Now what is your gender?", Split("Stallion;Mare", ";"), false) {
    player.gender = result
    ShowMenu ("Now what about your race?", Split("Earth;Pegasus;Unicorn", ";"), false) {
      player.race = result
      if (player.race = earthpony) {
        player.strength = 5
        player.defense = 4
        player.speed = 3
        player.hp = 20
      }
      else if (player.race == Pegasus) {
        player.strength = 4
        player.defense = 4
        player.speed = 5
        player.hp = 18
      }
    }
  }
}

if (player.race = earthpony) {
This line tests if the player's race is an object with the name "earthpony".

This fails, because there is no such object.

You probably meant:
if (player.race = "Earth") {

which tests if player.race is the word "Earth"

In script, a word with quotes around it is a string, a piece of text. A word without quotes is a bareword; which is either a function, a variable, or an object. If there isn't a function, variable, or object with that name, you get an error.

You also have == in the second if statement. Some programming languages use a double-equals sign to compare things, but Quest doesn't.


Thank you that helps. Now how do you make the values appear for the player to see. Right now strength, defense, etc are status attributes.


You can do in Text Processor Scripts in messages.

You have {player.strength} strength and {player.agility} agility. Your race is {player.race}.

You can also use these like this for if-scripts.

if (player.strength>=10) {
}

and so on :) Does that help?

Anonynn.


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


Data Types:

Strings vs Objects

(pay attention to the differences between the two below: note the use double quotes vs the use of no double quotes, and, the use of created/existing Objects vs the use of no created/existing Objects)

<!--
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Using Strings:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-->

<game name="example_game">

  <attr name="color_string_attribute" type="string">unknown</attr>

  <attr name="color_stringlist_attribute" type="stringlist">

    <value>red</value>
    <value>blue</value>
    <value>yellow</value>

  </attr>

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

    show menu ("Color?", game.color_stringlist_attribute, false) {

      game.color_string_attribute = result

      // using 'if' Script/Function:

      if (game.color_string_attribute = "red") {
        msg ("R")
      }
      else if (game.color_string_attribute = "blue") {
        msg ("B")
      }
      else if (game.color_string_attribute = "yellow") {
        msg ("Y")
      }

      // or, instead, using 'switch-case' Script/Function:

      switch (game.color_string_attribute) {
        case ("red") {
          msg ("R")
        }
        case ("blue") {
          msg ("B")
        }
        case ("yellow") {
          msg ("Y")
        }
      }

      // end

      // using "normal" scripting:

      msg ("Color: " + game.color_string_attribute)

      // or, using the 'text processor commands' scripting:

      msg ("Color: {game.color_string_attribute}")

      // end

    }

  </attr>

</game>

<!--
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Using Objects:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-->

<game name="example_game">

  <attr name="color_object_attribute" type="object">unknown</attr>

  <attr name="color_objectlist_attribute" type="objectlist">

    <value>red</value>
    <value>blue</value>
    <value>yellow</value>

  </attr>

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

    show menu ("Color?", game.color_objectlist_attribute, false) {

      game.color_object_attribute = result

      // using 'if' Script/Function:

      if (game.color_object_attribute = red) {
        msg ("R")
      }
      else if (game.color_object_attribute = blue) {
        msg ("B")
      }
      else if (game.color_object_attribute = yellow) {
        msg ("Y")
      }

      // or, instead, using 'switch-case' Script/Function:

      switch (game.color_object_attribute) {
        case (red) {
          msg ("R")
        }
        case (blue) {
          msg ("B")
        }
        case (yellow) {
          msg ("Y")
        }
      }

      // end

      // using "normal" scripting:

      msg ("Color: " + game.color_object_attribute)

      // or, using the 'text processor commands' scripting:

      msg ("Color: {game.color_object_attribute}")

      // end

    }

  </attr>

</game>

<object name="unknown">
</object>

<object name="red">
</object>

<object name="blue">
</object>

<object name="yellow">
</object>

using scripting:

<!--
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Using Strings:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-->

<game name="example_game">

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

    game.color_string_attribute = "unknown"

    // using the 'split' Script/Function:

    game.color_stringlist_attribute = split ("red;blue;yellow", ";")

    // or, instead, using this stuff:

    game.color_stringlist_attribute = NewStringList ()
    list add (game.color_stringlist_attribute, "red")
    list add (game.color_stringlist_attribute, "blue")
    list add (game.color_stringlist_attribute, "yellow")

    // end

    show menu ("Color?", game.color_stringlist_attribute, false) {

      game.color_string_attribute = result

      // using 'if' Script/Function:

      if (game.color_string_attribute = "red") {
        msg ("R")
      }
      else if (game.color_string_attribute = "blue") {
        msg ("B")
      }
      else if (game.color_string_attribute = "yellow") {
        msg ("Y")
      }

      // or, instead, using 'switch-case' Script/Function:

      switch (game.color_string_attribute) {
        case ("red") {
          msg ("R")
        }
        case ("blue") {
          msg ("B")
        }
        case ("yellow") {
          msg ("Y")
        }
      }

      // end

      // using "normal" scripting:

      msg ("Color: " + game.color_string_attribute)

      // or, using the 'text processor commands' scripting:

      msg ("Color: {game.color_string_attribute}")

      // end

    }

  </attr>

</game>

<!--
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Using Objects:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-->

<game name="example_game">

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

    create ("unknown")
    create ("red")
    create ("blue")
    create ("yellow")

    game.color_object_attribute = unknown

    // using the 'split' Script/Function:

    // Can NOT use the 'split' for creating Object Lists

    // using this stuff:

    game.color_objectlist_attribute = NewObjectList ()
    list add (game.color_objectlist_attribute, red)
    list add (game.color_objectlist_attribute, blue)
    list add (game.color_objectlist_attribute, yellow)

    // end

    show menu ("Color?", game.color_objectlist_attribute, false) {

      game.color_object_attribute = result

      // using 'if' Script/Function:

      if (game.color_object_attribute = red) {
        msg ("R")
      }
      else if (game.color_object_attribute = blue) {
        msg ("B")
      }
      else if (game.color_object_attribute = yellow) {
        msg ("Y")
      }

      // or, instead, using 'switch-case' Script/Function:

      switch (game.color_object_attribute) {
        case (red) {
          msg ("R")
        }
        case (blue) {
          msg ("B")
        }
        case (yellow) {
          msg ("Y")
        }
      }

      // end

      // using "normal" scripting:

      msg ("Color: " + game.color_object_attribute)

      // or, using the 'text processor commands' scripting:

      msg ("Color: {game.color_object_attribute}")

      // end

    }

  </attr>

</game>

Lastly, note that you can convert a String to an Object, and an Object to a String:

// using these examples:

game.color_string_attribute = "red"

create ("red")
game.color_object_attribute = red

// conversions of them:

game.color_object_attribute = GetObject (game.color_string_attribute) // for the 'GetObject' to work, you need to have existing/created that Object, else it returns 'null' and/or an error message, and in my example, we created our 'red' Object, so meet this requirement already

game.color_string_attribute = game.color_object_attribute.name


ask if you need help with anything


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


"Now how do you make the values appear for the player to see. Right now strength, defense, etc are status attributes Richer25)"


you can display them yourself, for an example using a Command (so you can just type in 'stats' to see them whenever you want):

(but there's other ways as well, such as using Objects and Verbs/Script_Attributes, instead of, or along with, using Commands)

<command name="stats_command">
  <pattern>stats</pattern>
  <script>
    ClearScreen
    msg ("Character Screen")
    msg ("")
    msg ("Name: {player.alias}")
    msg ("Sex: {player.sex}")
    msg ("Age: {player.age_integer} ({player.age_string})")
    msg ("")
    msg ("Race: {player.race}")
    msg ("Class: {player.class}")
    msg ("")
    msg ("Level: {player.alias}")
    msg ("Experience: {player.experience}")
    msg ("Currency: {player.currency}")
    msg ("")
    msg ("Life: {player.life}")
    msg ("Mana: {player.mana}")
    msg ("Stamina: {player.stamina}")
    msg ("")
    msg ("Strength: {player.strength}")
    msg ("Endurance: {player.endurance}")
    // etc stats
    wait {
      ClearScreen
    }
  </script>
</command>

and/or you can use the 'statusattributes' to display them in the status pane during game play too:

http://textadventures.co.uk/forum/quest/topic/5387/i-really-need-help#37375 (my step by step guide on creating you own demo game with creating and learning how to use/do the status attributes)

and here's a link on Attributes and the 'if' Script/Function usage too:

http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk


ask if you need help with anything


I think I might have phrased my question wrong. What I mean is that when the game starts there is a box that shows the stats and I wanted to know how to make the values appear in that box. I want to post a pic of what I mean but not sure how to do that here.


I think I might have phrased my question wrong. What I mean is that when the game starts there is a box that shows the stats and I wanted to know how to make the values appear in that box. I want to post a pic of what I mean but not sure how to do that here.

OK, you want to make them into status attributes.

Click on the "game" object, and go to the "Player" tab. There's a drop-down list to choose which object is the player. Underneath that is a list that you can add attributes to. When you add something, it gives you two columns, "key" and "value".

In the "key" column you should put be an attribute name. So if you want to display the value of player.strength, you would put strength.
In the "value" column, put how you want it to appear in the side panel. For example Strength: !. The ! will be replaced by the actual value of player.strength in-game.


So I have this issue where the description of the room is triggered before the player finishes creating the character. Is there a way to get that to wait until after the character creation is done and also have it print a different message that I already have set up in the "Before entering the room for the first time:" script


K.V.

Make a backup copy of your game before you try this!


Put the character creation stuff in the start script.

(Moving the player to the first room at the end should  happen automatically. So, if your script moves the player upon completion, the room description would be displayed twice (I think).)


The character creation is already in the start script but the player does start in the first room. I was thinking of creating another room for him to start in and as soon as the player creation is done move the player into the other room (The first one)


I was thinking of creating another room for him to start in and as soon as the player creation is done move the player into the other room (The first one)

Thhat's what most people do.


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

Support

Forums