Having problems with game stats
Nile
14 Jul 2016, 18:13Good evening,
I'm writing a gamebook and want to display the game stats, such as lp and score on every page. But I can't figure out how: There seem to be lots of possibilities to set a variable to a value etc... but no ways to create it. So, the game always asks for the variable, it can't find the variable.
My question is: How can I create a variable or display the game stats in general?
Thankful greetings
hegemonkhan
14 Jul 2016, 18:49Displaying your game stats on every Page:
Pages -> 'game' Game Page -> 'Script' Tab -> (see below)
add new script -> 'output' section/category -> 'print a message' Script -> print [EXPRESSION] game.lp // is it 'ip' or 'Lp' or what does (i/L)p stand for? (as I can't tell cause of stupid font, lol)
add new script -> 'output' section/category -> 'print a message' Script -> print [EXPRESSION] game.score
Creating your game stats:
// your first page (which is assigned by which Page has the 'player' Player Page inside of it):
'page or page1 or page0' Page -> 'Page' Tab -> Page Type: [script] or [script+text] -> Script -> (see below)
add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> set variable game.Ip = [EXPRESSION] YOUR_STARTING_VALUE_FOR_IT // or (using 'Lp'): set variable game.lp = [EXPRESSION] YOUR_STARTING_VALUE_FOR_IT
add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> set variable game.score = [EXPRESSION] YOUR_STARTING_VALUE_FOR_IT
Nile
26 Jul 2016, 18:05Wow, thanks! Great answer. Sorry, was busy - hollidays... Thanks again ;)
Nile
27 Jul 2016, 14:05Hm. I've still a problem: when I do what you say I get the following error: "Error running script: Object reference not set to an instant of an object."
hegemonkhan
27 Jul 2016, 19:40could you give more information? what did you do? could you post your relevent code, so we can trouble shoot it for you?
I think the error means that (you likely) don't have it matching up with your Object's name...
Nile
28 Jul 2016, 09:57Hi,
sure.
Game -> script -> add new script -> print a message -> print expression -> game.lp
startseite (my first page, this one with the player) -> page type: script + text -> add new script -> set variable or attribute -> set expression game.lp = 10
The code looks like this:
game.lp = 10
msg (game.lp)
When pressing play, the following error appears:
Error running script: Object reference not set to an instant of an object.
hegemonkhan
28 Jul 2016, 11:50I tested it and it worked, except that it can't display the 'lp' Integer Attribute upon entering the first page, as it's the first page that creates the Attribute and sets its initial value (once this occurs, then you won't have any issues with using/displaying your 'lp' Integer Attribute). I don't think you can do anything about this through scripting, except by "cheating" in just having the first page after it creates/sets the 'lp' Integer Attribute and its value, to have a 'msg/print a message [expression]' Script after it, to display this Attribute on the first page. Otherwise, you can also just go into the entire game code, and code in the 'lp' Integer Attribute directly into your 'game' Object, thus it's already there upon game loading/initialization as you choose to play your game.
By the way, through scripting, you can create/set Attributes also upon/into/to the 'player' Player Object. So you can split up the Attributes as needed between the 'player' Player Object and the 'game' Game Object. I'm not sure whether you can directly code in the Attributes to the 'player' Player Object in the game code itself (maybe you can, maybe you can't --- As I'm not sure if the GameBook is 'hard-coded' in its limitations or whether it's Editor's displayed features/options are merely limited but still exist and are able to be done).
here's the game code that works for me:
(I used 'life' as the name/label for my Integer Attribute; this would be equivalent to your 'lp' Integer Attribute, if my guess is right that 'lp' stands for life/hit points, lol)
(Also, I created the Attribute on the 'player' Player Object, not the 'game' Game Object --- I'l switch over to the 'game' Game Object, to see if this is possibly the/a cause of your error/s, get back to, you/my post, in a sec... lol)
<asl version="550">
<include ref="GamebookCore.aslx" />
<game name="testing game stuff">
<gameid>some generated random string hash for online/Alex' quest servers to ID games, or maybe for offline/quest.exe too, I think, and I am too lazy to try to write it here, lol, so I wrote this instead, laughs</gameid>
<version>1.0</version>
<firstpublished>2016</firstpublished>
<roomenter type="script">
msg ("Life: " + game.life)
// for the first room (as it can't display the Attribute via this example's method used), it looks like this:
// Life: (blank)
//
// when you click on the page link to go page 2 or 3, now it'll display the Attribute (as it now has been created/set):
// Life: 500
</roomenter>
</game>
<object name="Page1">
<inherit name="scripttect" />
<description>Page 1, blah blah blah</description>
<options type="simplestringdictionary">Page2 = This Link goes to page 2; Page3 = And this link goes to page 3</options>
<script type="script">
player.life = 500
</script>
<object name="player">
<inherit name="defaultplayer" />
</object>
</object>
<object name="Page2">
<description>Page 2, blah blah blah</description>
</object>
<object name="Page3">
<description>Page 3, blah blah blah</description>
</object>
</asl>
not sure if this is also the possible cause of your error:
startseite (my first page, this one with the player) -> page type: script + text -> add new script -> set variable or attribute -> set expression game.lp = 10
but it should look like this:
startseite (my first page, this one with the player) -> page type: script + text -> add new script -> 'variables' category/section -> 'set variable or attribute' Script -> set variable game.lp = [expression] 10
set variable game.lp = [expression] 10
is the same as this in code:
game.lp = 10
which both are the same as this in code too:
<game name="blah">
<attr name="lp" type="int">10</attr>
</game>
Nile
28 Jul 2016, 12:02Oh, forgot to mention that its "game.lp = expression 10"...
Nile
28 Jul 2016, 12:13Oh, you're right. it works. Thanks! Is there also a possibility to remove this from some pages as I also created help pages?
hegemonkhan
28 Jul 2016, 13:15This is a bit more complicated... at least especially since I'm not that familiar with the GameBook...
I think the easiest solution would be to "cheat":
have the 'game' Game Object's 'roomenter' Script Attribute, stay the same, displaying your 'lp' and/or other various stats.
and then for the Pages that you don't want the stats to be displayed, such as your 'help' pages, simply change them to 'Page Type: [script] or [script+text]', if they aren't already set as so, and add in this script (not sure how to do it through the GUI~EDitor, hopefully you can find it if its a script option or figure it out): ClearScreen
so, while it displays the stats on the unwanted pages, your very first page script is to clear the screen, wiping out/removing those unwanted stats from being displayed effectively, hehe
in code, it would like look this:
<game name="blah">
<attr name="roomenter" type="script">
msg ("Life: " + game.lp)
</attr>
</game>
<object name="help_page_1">
<attr name="description" type="string/script">blah</attr> // I'm not sure how the 'description' Attribute works with the GameBook (I don't know if its the same as in the Text Adventure or not) and the 'roomenter' Script... so, this Attribute too may need the 'ClearScreen' Script as its first script...
<attr name="script" type="script">
ClearScreen // this should happen too fast for the person playing your game to see the unwanted displayed stats (game.lp) before they're cleared, thus effectively its as if you never displayed the stats.
msg ("Your help content then goes here")
</attr>
</object>
Nile
28 Jul 2016, 14:34your a genius, thanks! this solution is simple and effective ;)