Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Two probably very noobish questions

Hello! Reviving my Twine account (turns out moving house makes you quite busy) to ask some questions:

1. Is there any way to incoporate a Dungeons and Dragons-like dice roll into the game? i.e. a random number generator that dictates how well the player survives an encounter/incident, preferably between 1 and 20.

2. I'm having an issue with my character creation variables not changing. I'm sure this just me missing something obvious but I've been over them a million times and I can't work out what the issue is.

In the Start passage I set all of the variables as so:
<<set $playerName = "Unknown"; $race = "Unknown"; $age = "Unknown"; $weapon = "None"; $gold = 50; $other = "None">>
The only one that changes is the name (using the Nameinput macro I found years ago, not sure where its from sorry).

Here's the passage that's meant to change the race and weapon:
Are you a Dwarf, and Elf, or Human?

[[Dwarf|Name][$race = "Dwarf"; $weapon = "Dwarven Axe"]]
[[Elf|Name][$race = "Elf"; $weapon = "Forest Bow"]]
[[Human|Name][$race = "Human"; $weapon = "Steel Sword"]]

And the one for age:
And finally, <<print $playerName>>, how old are you?

[[12 - 20 (Young)|Begin][$age = "Young"]]
[[21 - 35 (Adult)|Begin][$age = "Adult"]]
[[36 - 50 (Older Adult)|Begin][$age = "Older Adult"]]
[[50 - 70 (Old)|Begin][$age = "Old"]]
[[ 70 + (Very Old) |Begin][$age = "Very Old"]]
As I said I'm sure the problem here is very nooby and easy to fix, but I'm just staring at it blankly right now, and could use another set of eyes to tell me whats up!

Thanks

Comments

  • Sorry that I don't have time to write an answer specifically to your questions (or really read them very well), but you might find these two threads interesting:

    Example Turn-Based RPG (Pre-Alpha v. 0.4)
    Objects are Your Friends: How & Why to Use JavaScript Objects for Total Newbies

    Hope they help!
  • As far as the dice roll, I can tell you that you're going to want to use <<set $variable to random(1,20)>>. I don't know about the character variables, though.

  • Thank you both of you for your help on the dice roll -- I'll start looking into it this evening and come back with any questions.

    Sadly I am kind of stuck until I can sort out the Character variables...I might just try rewriting them in case I've made a silly mistake I just can't see.
  • When asking for help it is a good idea to state which of the Story Formats and version of Twine you are using as it sometimes makes a difference in the advice given.

    I created a test story using the example passages you supplied and found no problems with the variables, I have attached it so you can see if there is a difference between what I did and your own story.

    It is suggested by the creator of Twine 1 that you use a StoryInit passage to setup your variables and to use the 'to' keyword instead of an equals sign when doing variable assignments.

    <<set $variable to "value">>
    or
    [[Select this link|Some Passage][$variable to "value"]]
  • Quenen wrote:

    1. Is there any way to incoporate a Dungeons and Dragons-like dice roll into the game? i.e. a random number generator that dictates how well the player survives an encounter/incident, preferably between 1 and 20.


    Your code looks fine to me. Check to see that you are not using $name in one place and $Name in another, and that you didn't accidentally leave something like <<set $name = "Unknown>> at the top of the page you're loading.

    B
  • Another option for randomness is the <<set $thisIsAVariable = Math.floor(Math.random()*x)>> Code.
    Replace the x For the amount of different options you want avaliable, and for age you could write this-
    <<set $thisIsAVariable = Math.floor(Math.random()*x)>>
    You are <<print $thisIsAVariable>> Years old.
    That will assign the character a random age, from 0 to whatever number you want X to be.
    As for the character, it will be more complicated, but this is what I can do.
    <<set $thisIsAVariable2 = Math.floor(Math.random()*x)>>
    <<if $thisIsAVariable2 is "0">> You are a Dwarf.<<endif>>
    <<if  $thisIsAVariable2 is "1">> You are a Human<<endif>>

    And you create  however many races X is -1.
    As for randomness, What you would do is use the same randomness, but replace the variables and X would Equal 21.
    Hope I helped,
    Bladezy Boo
  • This post by TheMadExile explains how to use the random function built into each of the story formats.

    Remember that there is a difference between actual numbers (eg 1,2,3,..) and text values/strings that look like a number but aren't  (eg "1", "2",...).
  • Yeah, I have a bad habit of doing that. still don't get the difference.
  • Bladezyboo wrote:

    Yeah, I have a bad habit of doing that. still don't get the difference.


    A string (the text between two quotes) is just a series of characters (letters,numbers,symbols), and even though the contents may look like a word or a number, it is not actually that thing. So if I have the string value "dog" it is not an actual dog nor is a "hammer" an actual hammer, in the same way the string value "123" is not the actual number 123.

    You can do mathematics on numbers and numeric variables (ones that store numbers), generally* you cant do it to strings and string variables though you can use the plus symbol to concatenate two strings.

    Add two numbers:
    $var = 123 + 543 => 666

    Concatenate two strings:
    $var = "123" + "543" => "123543"
    I hope this has not made you more confused! lol

    * Some programming languages are 'smart' and try to convert  value of one data type into another for you and this is known as "Data Type Casting". (Casting for short)
    The problem is should it cast the number into a string or the string into a number?

    You have the following assignment:
    $var = 123 + "543"

    Should the lang. convert the number 123 into a string and do a concatenation?
    $var = "123" + "543" => "123543"

    Or should it convert the string "543" into a number?
    $var = 123 + 543 => 666
    If the lang. knows the data type of the variable ($var) the result is being stored into it can use this information to determine which cast to do, but generally they default to casting everything into strings.
  • Hmm... I think i get it...
    So "123" would be one and two and three, rather than one hundred and twenty three?
  • Bladezyboo wrote:

    Hmm... I think i get it...
    So "123" would be one and two and three, rather than one hundred and twenty three?

    Yes.

    "123" is the character "1" (one) and the character "2" (two) and the character "3" (three) joined together into a string.
Sign In or Register to comment.