Question on coding of gamebooks
adrao
16 Nov 2014, 18:28Probably a very basic question regarding coding:
I want to display the number of hit points left, so that it goes something like this
msg ("Your last blow knocks your oponent unconcious. Sweating heavily, you congratulate yourself on your win. You took a bit of a beating during the fight, meaning you only have a few Hit Points left, more specifically:")
msg (player.hp)
But this basically means that the number of HP appears on a different line. Is there any way to combine this, or do this in a better way?
Thanks in advance!
I want to display the number of hit points left, so that it goes something like this
msg ("Your last blow knocks your oponent unconcious. Sweating heavily, you congratulate yourself on your win. You took a bit of a beating during the fight, meaning you only have a few Hit Points left, more specifically:")
msg (player.hp)
But this basically means that the number of HP appears on a different line. Is there any way to combine this, or do this in a better way?
Thanks in advance!

Pertex
16 Nov 2014, 18:56Did you try this?
msg ("Your last blow knocks your oponent unconcious. Sweating heavily, you congratulate yourself on your win. You took a bit of a beating during the fight, meaning you only have a few Hit Points left, more specifically:" + player.hp)
msg ("Your last blow knocks your oponent unconcious. Sweating heavily, you congratulate yourself on your win. You took a bit of a beating during the fight, meaning you only have a few Hit Points left, more specifically:" + player.hp)
HegemonKhan
16 Nov 2014, 19:11print a message -> [MESSAGE]: text
msg ("Hi, my name is HK.")
outputs: Hi, my name is HK.
---------------
print a message -> [EXPRESSIONS]: text + variables
player.alias = "HK"
msg ("Hi, my name is " + player.alias + ".")
outputs: Hi, my name is HK.
---------------
the secret to writing EXPRESSIONS (text+variables) is to break them into 2 chunks, let's do a more complex 'msg' though:
player.alias = "HK"
player.gender_string = "male"
player.race_string = "human"
player.class_string = "warrior"
msg (player.alias + " is a " + player.gender_string + " " + player.race_string + " " + player.class_string + ".")
which outputs: HK is a male human warrior.
----------
and the 2 chunks:
"text (including a space)"
+ Object_name.Attribute_name (or Variable_name) +
OR
"text (including a space, as a space is a textual character~symbol)"
+
Object_name.Attribute_name (or Variable_name)
---------
the chunks (connected via adding them together, yes you're 'adding, literally~physically putting, strings' together: "4"+"5"="45" or "a"+"b"="ab" or "a"+"b"+"c"="abc", vs 4+5=9, hehe):
player.alias
+
" is a " ~~~~~~~~~~~~~ conceptually: "(space) is (space) a (space)"
+
player.gender_string
+
" " ~~~~~~~~~~~~~~ conceptually: "(space)"
+
player.race_string
+
" " ~~~~~~~~~~~~~~ conceptually: "(space)"
+
player.class_string
+
"." ~~~~~~~~~~~~ conceptually (as it's hard to see it, well for my bad eyes anyways, lol): "(period~dot)"
~OR~
player.alias +
" is a "
+ player.gender_string +
" "
+ player.race_string +
" "
+ player.class_string +
"."
msg ("Hi, my name is HK.")
outputs: Hi, my name is HK.
---------------
print a message -> [EXPRESSIONS]: text + variables
player.alias = "HK"
msg ("Hi, my name is " + player.alias + ".")
outputs: Hi, my name is HK.
---------------
the secret to writing EXPRESSIONS (text+variables) is to break them into 2 chunks, let's do a more complex 'msg' though:
player.alias = "HK"
player.gender_string = "male"
player.race_string = "human"
player.class_string = "warrior"
msg (player.alias + " is a " + player.gender_string + " " + player.race_string + " " + player.class_string + ".")
which outputs: HK is a male human warrior.
----------
and the 2 chunks:
"text (including a space)"
+ Object_name.Attribute_name (or Variable_name) +
OR
"text (including a space, as a space is a textual character~symbol)"
+
Object_name.Attribute_name (or Variable_name)
---------
the chunks (connected via adding them together, yes you're 'adding, literally~physically putting, strings' together: "4"+"5"="45" or "a"+"b"="ab" or "a"+"b"+"c"="abc", vs 4+5=9, hehe):
player.alias
+
" is a " ~~~~~~~~~~~~~ conceptually: "(space) is (space) a (space)"
+
player.gender_string
+
" " ~~~~~~~~~~~~~~ conceptually: "(space)"
+
player.race_string
+
" " ~~~~~~~~~~~~~~ conceptually: "(space)"
+
player.class_string
+
"." ~~~~~~~~~~~~ conceptually (as it's hard to see it, well for my bad eyes anyways, lol): "(period~dot)"
~OR~
player.alias +
" is a "
+ player.gender_string +
" "
+ player.race_string +
" "
+ player.class_string +
"."
adrao
16 Nov 2014, 19:32Thanks guys, much appreciated!!!

jaynabonne
16 Nov 2014, 19:39You can also just do:
in your text field. Or in your msg. (Text processor magic.)
Your last blow knocks your oponent unconcious. Sweating heavily, you congratulate yourself on your win. You took a bit of a beating during the fight, meaning you only have a few Hit Points left, more specifically: {player.hp}.
in your text field. Or in your msg. (Text processor magic.)