Help in codeview how Attributes/Stats work (Gamebook)? [Solved]

Beginner working on a game.
A player's stats will change when the player goes to a certain page.

Ex. Page1
Do you want to learn to dance?
Yes [leads to Page2]
No [leads to Page3]

If the player chooses Yes, then the player will gain a new skill [Dance +1]
And if the player chooses No then the player will not have that skill [Dance 0]

Then somewhere in the future, let's say Page32, the Dance skill is required.
If they have [Dance +1] then they will get a "Wow you dance good!" message and will level up [Dance +2]
But if they answered No earlier, they they will get a "You dance... terrible." message and will not level up.

Something like this? I understand better in codeview or screenshots. Thanks in advance!


K.V.

Hello.

This may help you:

http://textadventures.co.uk/forum/quest/topic/psoh-wmvhugkpz_ttsvdqa/making-an-object#3e6dc09e-d02c-4765-97cc-758001c4beaf


here's my (so far, failed, sighs) attempt at helping too (my posts might make more sense if you use KV's help/post/link and then compare it to/with my posts/help, lol):

http://textadventures.co.uk/forum/quest/topic/psoh-wmvhugkpz_ttsvdqa/making-an-object#809d99a5-76af-4cf4-bf0c-2a912afee85a

http://textadventures.co.uk/forum/quest/topic/psoh-wmvhugkpz_ttsvdqa/making-an-object#d0ec0ac9-7fff-45b3-a630-c700f558b8d1


ask if you need help with anything


Careful how you think about your skills/attributes. In your example, the player actually should get the attribute in either case. It's only the value of the skill that you are changing. You are actually using the value of zero to represent the player not having the skill.

When the player does not have the skill, they still have the attribute to represent it:

player.dance = 0

And "getting" the skill looks like this:

player.dance = player.dance + 1

Good luck with your game!


an example on whatever pages that you want to check and manipulate a skill:

(the code below can be adjusted to whatever mechanics you want for checking and/or acting-upon/manipulting a skill, it's just a simple quick code example only)

if (player.dance = 0) {
  msg ("NOTHING HAPPENS AS YOU NEVER DEVELOPED THE/A 'DANCE' SKILL")
} else {
  player.dance = player.dance + 1 // or whatever Value (doesn't have to be '1') or whatever arithmetic operation (doesn't have to be addition: '+')
 msg ("You further developed your 'dance' skill)
}

you can have a design where the player doesn't have the Attribute, but I think that takes more work (adding/removing from lists), so I think it's easier/more-simple to just have the Attribute with '0', and check if its '0' or not, instead of adding/removing from lists and checking: if (HasAttribute (XXX)), or not...


What HK says is true, but you should probably try to avoid using lists in gamebook mode, as it can be more complicated. As a beginner, I highly recommend just using attributes on page objects.


you can have a design where the player doesn't have the Attribute, but I think that takes more work (adding/removing from lists)

Not really more work:

if (not HasInt (player, "dance")) {
  msg ("You try to dance, but you never learned the basics")
} else {
  player.dance = player.dance + 1
  msg ("You practice dancing, and get a little better. Dance level: {player.dance}.")
}

K.V.

Page1

image


Page2

image
image
image


Page3

image
image
image


Page4

image


quit

image
image


Entire game:

<!--Saved by Quest 5.7.6606.27193-->
<asl version="550">
  <include ref="GamebookCore.aslx" />
  <game name="Dancin', Dancin', Dancin'!">
    <gameid>2de90996-b0f0-4de9-996b-2acd620ff34d</gameid>
    <version>1.0</version>
    <firstpublished>2018</firstpublished>
    <setcustomwidth type="boolean">false</setcustomwidth>
  </game>
  <object name="Page1">
    <description>Do you want to learn to dance?</description>
    <options type="stringdictionary">
      <item>
        <key>Page2</key>
        <value>Yes</value>
      </item>
      <item>
        <key>Page3</key>
        <value>No</value>
      </item>
    </options>
    <object name="player">
      <inherit name="defaultplayer" />
    </object>
  </object>
  <object name="Page2">
    <inherit name="scripttext" />
    <description>You spend months learning, and you can now do the Butterfly (also known as "The Tootsie Roll")!</description>
    <script type="script">
      set (player, "Dance", 1)
    </script>
    <options type="stringdictionary">
      <item>
        <key>Page4</key>
        <value>Continue...</value>
      </item>
    </options>
  </object>
  <object name="Page3">
    <inherit name="scripttext" />
    <description>You spend months eating, sitting around, and interacting with fiction. </description>
    <script type="script">
      set (player, "Dance", 0)
    </script>
    <options type="stringdictionary">
      <item>
        <key>Page4</key>
        <value>Continue...</value>
      </item>
    </options>
  </object>
  <object name="Page4">
    <description><![CDATA[<h3>6 months later...</h3><br/><br/>At the big event, it's time to shake your money-maker.  There's no escaping it.  So, you give it your best shot.<br/><br/>{if player.Dance<>0:"Wow you dance good!" you hear from somewhere in the crowd of attractive faces which have gathered around you.}{if player.Dance=0:"You dance... terribly," mumbles a blind man, just before Moonwalking away, leaving you stupid-looking and alone (as opposed to just stupid looking).}<br/><br/><h1>{if player.Dance<>0:YOU WIN!}{if player.Dance=0:You have lost. }</h1>]]></description>
    <options type="stringdictionary">
      <item>
        <key>Page1</key>
        <value>Try Again</value>
      </item>
      <item>
        <key>quit</key>
        <value>Quit</value>
      </item>
    </options>
  </object>
  <object name="quit">
    <inherit name="script" />
    <script type="script">
      JS.uiShow ("#gamePanes,#gamePanesFinished")
      JS.uiHide ("#gamePanesRunning")
      JS.setCss ("#gamePanesFinished", "background:"+game.defaultbackground+";border:1px solid black;padding:12px;")
    </script>
  </object>
</asl>

Hello! Thank you all for your help!
I checked it all out but I'm still having a problem in one part. How do I set object? When I click the "set a variable or attribute" it doesn't show the "Set Object [name] [player]". It only shows "set variable [in this space] expression = [in this space]".


K.V.

Sorry. I'm used to text adventures.

...and I work in code view, pulling the screenshots from the GUI afterwards.


METHOD 1 (easiest)


METHOD 2 (which I used)


generic syntax:

set variable NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = [EXPRESSION] VALUE_OR_EXPRESSION

examples:

set variable player.alias = [EXPRESSION] "HK"
set variable game.state = [EXPRESSION] 0
set variable game.orc_dead = [EXPRESSION] false
set variable player.strength = [EXPRESSION] 100
set variable game.introduction = [EXPRESSION] "Welcome to my game, I hope you enjoy it, muwahaha!"
set variable Page1.visited = [EXPRESSION] true
set variable player.parent = [EXPRESSION] Page1

create ("Page99") // we need to create our 'Page99' Page Object, so it exists, lol
set variable Page99.description = [EXPRESSION] "This is the final page of the game"


K.V.
I followed as you said K.V.
Error running script: Invalid variable name '' in '='
This appeared in Page1.
It also appears when in Page 2 and 3. I don't know how to upload a screenshot but this is what I typed in Page2.

set (player, "Dance", "1")

And this is what I typed in Page3.

set (player, "Dance", "0")

I followed your instructions to write it in Code View. But the error running script appears.
The error appears in all pages (1-4).

For the last page, Page4. The IF code when player chose 'yes' remains as I have written it and appears to either choices.
{if player.Dance>0;"Wow you dance good!" they say.}
{if player.Dance<>0;"Wow you dance good!" they say.}
Either way it's typed, it appears like that to the screen and it appears whether the player learned to dance or not.

What do I do?

hegemonkhan
Thank you very much for the help. My question is as I mentioned above.
I tried to the player.dance = 0 code but I am still confused how I can add value whenever the player chooses the right choice that will trigger the "add value" to the skill.


Update:
I added Dance = 0 in the game > script and then I "set variable attribute"..
The Error running script: Invalid variable name '' in '=' disappeared in all pages.
The only problem I have is this.

{if player.Dance<>0;"Wow you dance good!" they say.}

The code doesn't work the way {if player.Dance=0:"You dance terribly." they say.} works.

I will continue to experiment with the code stuff. If any of you are available, please help me out. Thank you!


{if player.Dance<>0;"Wow you dance good!" they say.}

You have a semicolon (;) instead of a colon (:)


OOOH I see thank you thank you! It works now! Thank you!


If you're checking both in the same place, it might be easier to use "Wow, you dance {either player.Dance=0:terribly|good}!" they say.
(Think I remember how it works right)


Oooh, that looks easier. Thanks. I will use that. Thank you!


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

Support

Forums