How do I let the player choose a race/team? (Gamebook)

karinchan999
24 May 2018, 18:04

Once again thank you to all those who previously helped me with my problems, I was able to make more progress with the game and will continue to work on it. But now I am stuck with something again, please help me.

I've read several links on how to do the "choose gender/choose race" problems before but I couldn't figure it out.

  1. How do I do a game.race object/variable? I figured out how the player.strength stuff works. I saw in a comment in one post that there's like a long list of game.race, game.sex, game.etcetc and there's also a long list for player.damage, player.etcetc. So how do I do a game.race object? Is there a difference to what player.race does?
  2. How do I let the player choose a race?
    For example, the player has choices from [mage, elf, warrior].

I saw this on one link so I tried it. set variable [player.race] expression ["Elf"] and did the same to the other two choices. It's located in three separated pages

Page1; Elf
Page2: Mage
Page3: Warrior

So the text would be something like

You chose Elf (or player.race)!

So whenever I type the player's chosen race, I'll just use player.race or the correct code for it.

And on Page4 the results. But no matter what I do, it's either results is a blank or just a space. Please help me.
I am a beginner in this, I understand better in Code View or screenshots. Thank you in advanced!


K.V.
24 May 2018, 18:22

I understand better in Code View or screenshots.

I don't understand what you mean by this.

Do you understand better when we post code, or do you understand better when we post screen shots?


Please post your code so we can see what you've got so far. (That would be much more efficient than theorizing.)


JenniferCampbell
24 May 2018, 18:31

Just a couple hints.

  1. DON'T assign the 'race' attribute to the 'game' object (game.race = bad idea), as the game doesn't need a race - or there may be more than one race in the game.
  2. The format for variables, as you probably know, is OBJECT.ATTRIBUTE. A gamebook has a few default objects, 'game', 'player' and Pages ('Page1', 'Page2' etc.). These objects can have any type of attribute. Also, EVERY page that you create is a game object that can have attributes.
  3. Attributes (and even page names) are CASE-SENSITIVE. Meaning that 'game.gold' is different than 'game.GOLD' or 'game.Gold'.
  4. To display the value of an attribute in your text, you put it in curly braces, like so: {game.gold}. You have to do this in the text area, even in code view.

Good luck with your game!


K.V.
24 May 2018, 18:40

Basically,

You are probably want to save two different types of value when you are setting up stats: integers and strings.

INTEGERS are numbers which you will add, subtract, multiply, divide, etc.

STRINGS are words which you will print during play.


STRINGS

The "race" attribute will be a STRING. So:

player.race = "Human"

This could also be done like this:

set (player, "race", "Human")

To print it during play:

You chose the race {player.race}.

INTEGERS

When setting up an integer, make sure you do NOT use quotation marks!

I assume strength is a number, which will increase as the story unfolds if the player makes the proper choices.

player.strength = 50

This could also be done like this:

set (player, "strength", 50)

Either way, it's 50, not "50".

If we put "50", that would make it a STRING, which is a word, which can't be used in mathematical operations.


We print integer values just like we do string values:

Your strength is currently {player.strength}.

http://docs.textadventures.co.uk/quest/using_attributes.html


karinchan999
24 May 2018, 18:54

Hi K.V.
Yes I understand it better if someone posts a Code View that I can compare to what I did. Or a step by step screenshot.

Here's an update on what I discovered.
I used player.race and it works as the screenshot said from another link.
But when I used player.guide (because in the game, the player will choose a guide to guide him/her in the introduction part), that's where the result is a blank.

There are only certain words that the game can read?

Hi JenniferCampbell!
Thank you for the hints, I will keep note of it. I have a question though, what is the difference of game.(attribute) and player.(attribute)? And how do I make game.(attribute)?


K.V.
24 May 2018, 19:22

What are you putting in the code when you set up player.guide?

If you post that code here, we can look at it. Then, we can see what you are doing incorrectly. Then, we can help you.

If we do anything other than that, we're just guessing, and you're chasing your tail.


hegemonkhan
24 May 2018, 20:05

it's just like the real world:

(Object Name: sun)

Attribute Name: color
(Attribute Type: string)
Attribute Value: "yellow"

Attribute Name: shape
(Attribute Type: string)
Attribute Value: "round"

Attribute Name: type
(Attribute Type: string)
Attribute Value: "star"

Attribute Name: size_integer
(Attribute Type: integer: int)
Attribute Value: 432169 // approx in miles

Attribute Name: size_string_A
(Attribute Type: string)
Attribute Value: "432169 miles"

Attribute Name: size_string_B
(Attribute Type: string)
Attribute Value: "medium"

Attribute Name: is_bright
(Attribute Type: boolean)
Attribute Value: true

create ("sun") // creating our 'sun' Object
sun.color = "yellow"
sun.shape = "round"
sun.type = "star"
sun.size_integer = 432169
sun.size_string_A = "432169 miles"
sun.size_string_B = "medium"
sun.is_bright = true

an Object and its Attributes/traits/characteristics/etc


create ("joe")
create ("jim")

joe.hair_color = "brown"
jim.hair_color = "brown"

as you can see, joe.hair_color = "brown" and jim.hair_color =" brown", are two separate Attributes and thus exist at the same time, one belonging to 'joe' and the other to 'jim'

'joe.hair_color' is not the same as 'jim.hair_color'


Names (the 'name' String Attribute) are the IDs (think of 'names' as like DNA), so they must be unique, no two Object names can be the same, but you can have Attributes names the same if they're on different Objects (joe.hair_color = "brown" and jim.hair_color = "brown"), and lastly make sure you type the names in correctly, as quest is case sensitive:

joe.hair_color = "brown"
joe.Hair_color = "brown"

these are two different named (and thus two different) Attributes of (contained with) the 'joe' Object: 'hair_color' vs 'Hair_color'

again, make sure you got no typos... make sure you got the spellings of your names matching up correctly

for example, if you don't:

joe.hair_color = "brown"
joe.Hair_color = "brown"

// you'll get an error, as this Attribute doesn't exist, and thus the error when quest tries to find and do the check for/of it:
if (joe.hair_Color = "Brown") {
// scripting // this scripting will/can never happen
}


game.sex_stringlist_attribute = NewStringList ()
list add (game.sex_stringlist_attribute, "male")
list add (game.sex_stringlist_attribute, "female")

game.race_stringlist_attribute = NewStringList ()
list add (game.race_stringlist_attribute, "human")
list add (game.race_stringlist_attribute, "dwarf")
list add (game.race_stringlist_attribute, "elf")

game.guide_stringlist_attribute = NewStringList ()
list add (game.guide_stringlist_attribute, "wise owl")
list add (game.guide_stringlist_attribute, "old man")
list add (game.guide_stringlist_attribute, "visions")

msg ("Name?")
get input {
  player.alias_string_attribute = result
  ShowMenu ("Sex?", game.sex_stringlist_attribute, false) {
    player.sex_string_attribute = result
    ShowMenu ("Race?", game.race_stringlist_attribute, false) {
      player.race_string_attribute = result
      if (player.race_string_attribute = "human") {
        player.strength_integer_attribute = 5
        player.intelligence_integer_attribute = 5
      } else if (player.race_string_attribute = "dwarf") {
        player.strength_integer_attribute = 10
        player.intelligence_integer_attribute = 0
      } else if (player.race_string_attribute = "elf") {
        player.strength_integer_attribute = 0
        player.intelligence_integer_attribute = 10
      }
      ShowMenu ("Guide?", game.guide_stringlist_attribute, false) {
        player.guide_string_attribute = result
      }
    }
  }
}

DisplayList (game.sex_stringlist_attribute, true)
DisplayList (game.race_stringlist_attribute, true)
DisplayList (game.guide_stringlist_attribute, true)

msg ("Player Name: " + player.alias_string_attribute)
msg ("Player Sex: " + player.sex_string_attribute)
msg ("Player Race: " + player.race_string_attribute)
msg ("Player Strength: " + player.strength_integer_attribute)
msg ("Player Intelligence: " + player.intelligence_integer_attribute)
msg ("Player Guide: " + player.guide_string_attribute)

in code scripting:

NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION

in GUI/Editor scripting:

set variable NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = [EXPRESSION] VALUE_OR_EXPRESSION


'game' is an Object
'player' is an Object
'Page1' is an Object

// however you create a Page Object in the Game Book:
// (using the 'create' Script/Function in a Text Adventure for examples)
create ("Page70")
create ("Page80")
create ("Page90")
'Page70', Page80', and 'Page90' are Objects

just as in a Text Adventure:
create ("joe")
create ("jim"
create ("jeb")
'joe', 'jim', and 'jeb' are Objects

so, the difference between, for example:

game.hair_color = "brown"
and
player.hair_color = "brown"

is the same as the difference between, for example:

joe.hair_color = "brown"
and
jim.hair_color = "brown"

game.hair_color = "brown" and player.hair_color = "brown", are two separate Attributes

just as, jim.hair_color = "brown" and joe.hair_color = "brown", are two separate Attributes


JenniferCampbell
24 May 2018, 20:22

Hi Karin,
The difference between game.(attribute) and player.attribute is that 'game' and 'player' are objects that you can assign attributes to. For example, I use game.GOLD to keep track of ounces of gold available in the game and I use player.GOLD to keep track of how many ounces the player has. In most gamebooks, you assign an attribute to an object the first time the object and attribute are written together with a dot. Whether it's in a script or in the text editor usually doesn't matter, but I like to assign variables in scripts to keep things neat. If I want a random amount of gold available at the start of the game, I put script on the page the player starts on (the page with the player object under it):

  <object name="START">
    <inherit name="script" />
    <description type="string"></description>
    <options type="stringdictionary" />
    <script type="script">
      player.GOLD = GetRandomInt(10,100)
      msg ("What is your character's name?")
      GetInput() {
        player.alias = CapFirst (result)
        ClearScreen
      }
      MovePlayer (gender)
    </script>
    <object name="player">
      <inherit name="defaultplayer" />
    </object>

In the code above, the game starts with the page called "START" because the player object is under it, and a random amount of gold is assigned to the player. Then it asks for the player to enter a name. No matter what they type, it capitalizes their input and assigns it to 'player.alias'. Then it clears the screen and moves the player object to a page called "gender".


Another important hint: Any scripts assigned to the 'game' object will be run every turn (every time the player object is moved to another page).


karinchan999
25 May 2018, 05:17

Sorry, here is the code.

<roomenter type="script">
  guide = "Guide1"
  guide = "Guide2"
  guide = "Guide3"
</roomenter>
>

There.
I don't know how to block quote everything, it doesn't read when there's no block quote but this is it.


hegemonkhan
25 May 2018, 05:38
m```
(paste your code or wall of text here)
m```

but without the m's in front, to produce this:

(paste your code or wall of text here)

those weird characters/symbols is the key in the upper left of your keyboard, to the left of the '1' key (in the row of numbers at the top of keyboard) and above the left 'TAB' key, and if press-hold shift, it makes the tilde (~) character/symbol instead.


K.V.
25 May 2018, 06:11

Try changing that to:

  player.guide = "Guide1"
  player.guide = "Guide2"
  player.guide = "Guide3"

ALSO SEE:

https://github.com/KVonGit/QuestStuff/wiki/Posting-Code-to-the-TextAdventures-Forum


karinchan999
25 May 2018, 06:12
<!--Saved by Quest 5.7.6606.27193-->
<asl version="550">
  <include ref="GamebookCore.aslx" />
  <game name="Sample Training">
    <gameid>9873d63f-0d25-4b0b-8c0c-7d3b089a15f4</gameid>
    <version>1.0</version>
    <firstpublished>2018</firstpublished>
    <category>Simulation</category>
    <description type="string"></description>
    <defaultbackground>Black</defaultbackground>
    <defaultforeground>Cornsilk</defaultforeground>
    <defaultlinkforeground>GreenYellow</defaultlinkforeground>
    <roomenter type="script">
      guide = "Guide1"
      guide = "Guide2"
      guide = "Guide3"
    </roomenter>
  </game>
  <object name="Page1">
    <inherit name="scripttext" />
    <description>Choose a guide.</description>
    <options type="stringdictionary">
      <item>
        <key>Page10</key>
        <value>Guide1</value>
      </item>
      <item>
        <key>Page11</key>
        <value>Guide2</value>
      </item>
      <item>
        <key>Page9</key>
        <value>Guide3</value>
      </item>
    </options>
    <script type="script">
    </script>
    <object name="player">
      <inherit name="defaultplayer" />
    </object>
  </object>
  <object name="Page9">
    <inherit name="scripttext" />
    <description>You choose {player.guide}!</description>
    <options type="stringdictionary">
      <item>
        <key>Page12</key>
        <value>Continue</value>
      </item>
    </options>
    <script type="script">
      player.guide = "Guide3"
    </script>
  </object>
  <object name="Page10">
    <inherit name="scripttext" />
    <description>You choose {player.guide}!</description>
    <options type="stringdictionary">
      <item>
        <key>Page12</key>
        <value>Continue</value>
      </item>
    </options>
    <script type="script">
      player.guide = "Guide1"
    </script>
  </object>
  <object name="Page11">
    <inherit name="scripttext" />
    <description>You choose {player.guide}!</description>
    <options type="stringdictionary">
      <item>
        <key>Page12</key>
        <value>Continue</value>
      </item>
    </options>
    <script type="script">
      player.guide = "Guide2"
    </script>
  </object>
  <object name="Page12">
    <description>And so {player.race} will travel...</description>
  </object>
</asl>

Oh thank you it works!
This is the code. Please help me.


K.V.
25 May 2018, 06:15

Hey, HK! I just learned a trick!

Nest your example of posting code using 3 backticks within 4 backticks to get this:

```
code
```

Code View:

````
```
code
```
````

K.V.
25 May 2018, 06:20

Oh thank you it works!
This is the code. Please help me.

If it works, what else do you need help with?

Or did it get messed up somehow?

Why aren't the changes showing up in the code you posted?!?

EDIT

It looks like you just missed one spot, on the first page.


When you change that code and press 'Play' to test it, Quest will automatically save your changes. (I'm watching you closely, now! (wink, wink))


Change your script to this, then press 'Play' to test it:

  player.guide = "Guide1"
  player.guide = "Guide2"
  player.guide = "Guide3"

karinchan999
25 May 2018, 07:10

Hello K.V.!
The block quote problem I had, I couldn't post the code view because I didn't know how. HK helped me, that was the

Oh thank you it works!
This is the code. Please help me.

Yeah.
And I tried the script to...

player.guide = "Guide1"
player.guide = "Guide2"
player.guide = "Guide3"

Just as you instructed, and it works now! The game works just fine, thank you thank you thank you very much!
Thank you both of you! I am very happy!


K.V.
25 May 2018, 07:41

Yippee!

If you need any more help, don't hesitate to ask!

Happy gaming!


karinchan999
25 May 2018, 08:15

I will. Thank you again very much! :D


K.V.
25 May 2018, 08:56

That's some pretty good SPAM!

XanMag is awesome! (I say this ONLY because he wiped the SPAM off of this thread.)


JenniferCampbell
25 May 2018, 11:28

"That's some pretty good SPAM!"

Not at all. It was robotic and unimaginative. I give it a 3.5 out of ten. And that's only because he quoted me. It'd be a right 2.0, but for that.