Modeling a bidding system
Deckrect
10 Apr 2020, 22:00Hello, people. I am currently working on a project that demands a bidding system. Before I explain, lets just check the basics: It is essencially a gamebook, however, in order to preserve some of the functions I would need, I am using the editor in the Parser mode, then I stripped the compass, map, command line and left just objects and the inventory.
At some points in the game, the player must be able to press one of the buttons on an object in the room and run the script. (the easy part)
So, the game must ask the player how many Effort Points he/she/it wants bidding. So, the scripts must:
- Ask the player how many points he wants bidding.
2)Check if the player is biddin a negative value, what invalids the bidding.
3)Check if player.effort attribute is equal or greater than the bidding, or the bidding becomes invalid. (just as a negative bidding)
4)Reduce player.effort to player.effort - bidding.
5)Store the bidding, so i may apply bonuses and penalties andthen compare to a difficulty number.
I have absolutely no idea how modeling this. My initial idea was a window like poping up and asking how many points to bid, but as it seems it is only an option when you offer the player a Menu, what I would not like doing because I don't know well how to handle lists during the game and I don't want limiting the number of points in the bidding.
Can someone please cast some light over this issue and perhaps show me how I should put this code in the game. Once I can solve one bidding, all I need is copy/paste it through the game or use a function, but right now, I cannot make it work.
Thanks in advance.
Deckrect
12 Apr 2020, 00:43By the way, I have been doing some test and used the "show menu", giving player numbers as options. Once of the scripts as the menu's scrip involved subtracting the result (expressed by result, right?) from a variable named player.effort created "At game start". But the game tells something about not able to subtract things from INT32. Why it doesn't work?
mrangel
12 Apr 2020, 10:07By the way, I have been doing some test and used the "show menu", giving player numbers as options. Once of the scripts as the menu's scrip involved subtracting the result (expressed by result, right?) from a variable named player.effort created "At game start". But the game tells something about not able to subtract things from INT32. Why it doesn't work?
If you've asked the player for a number using ShowMenu
or get input
, it will be a string. You can't do maths with a series of characters, even if they are all digits. You would need to use ToInt (result)
instead, which converts it to a number you can do sums with.
If you use get input
to let the player type in a number, then you will also need to check IsInt (result)
to make sure that what they typed is actually a number.
hegemonkhan
12 Apr 2020, 15:53(filler for getting my edited post, updated/posted)
here's an example (in code, lazy), using a text adventure version (too lazy to look up a Game Book version), if you need help converting or doing this in a Game Book, let me know, and I can, help you with it getting it set up in the Game Book version
(you can change my/the 'bid_maximum' and 'bid_minimum' Integer Attributes in the 'bid_object' Object to whatever you want, I just arbitrarily/for-an-example used: '0' and '100', if for some reason you were to use a negative value for the 'bid minimum', then you might need a bit more coding/scripting to handle it, depending on what you want and/or with what quest is or is not able to do already with handling calculations involving negative values. Also, hopefully extremely obviously, your 'bid_maximum' needs to be greater than or equal to your 'bid minimum', and your Player's, aka as 'game.pov' in the code, 'effort' Integer Attribute has to be able to be greater than or equal to your 'bid_minimum' Integer Attribute of the 'bid_object' Object)
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="NAME_OF_GAME">
</game>
<object name="room">
<inherit name="editor_room" />
</object>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<attr name="parent" type="object">room</attr>
<attr name="effort" type="int">0</attr>
</object>
<object name="bid_object">
<inherit name="editor_object" />
<attr name="parent" type="object">room</attr>
<attr name="bid_valid_value" type="int">0</attr>
<attr name="bid_minimum" type="int">0</attr>
<attr name="bid_maximum" type="int">100</attr>
<attr name="bid" type="script">
<![CDATA[
msg ("Bid? (type in a value between: " + this.bid_minimum + " and " + this.bid_maximum + ")")
get input {
// edit:
// quest automatically (hidden from you) sets/stores your input to the 'result' variable
// result = YOUR_TYPED_IN_INPUT_ALWAYS_SET/STORED_AS_A_STRING_DATA_TYPE
if (IsInt (result)) {
vid_input_int = ToInt (result)
if (vid_input_int >= this.bid_minimum and vid_input_int <= this.bid_maximum) {
if (game.pov.effort >= vid_input_int) {
this.bid_valid_value = vid_input_int
game.pov.effort = game.pov.effort - vid_input_int
} else {
msg ("Error: wrong input, please try again, typing in a number value lesser than or equal to: " + game.pov.effort)
}
} else {
msg ("Error: wrong input, please try again, typing in a number value within the inclusive bounds of: " + this.bid_minimum + " to " + this.bid_maximum)
}
} else {
msg ("Error: wrong input, please try again, typing in a number value")
}
}
]]>
</attr>
<displayverbs type="stringlist">
<value>bid</value>
</displayverbs>
</object>
<verb>
<property>bid</property>
<pattern>bid</pattern>
<defaultexpression>You can't bid that!</defaultexpression>
</verb>
</asl>
Deckrect
12 Apr 2020, 18:12I am almost there, guys. But I confess I am having a hard time understanding the code. Actually, it seems to be too far complicated to what I actually need. I am trying to mashup it to Mrangel's pop-up input window, to make things more clear and not have to restore the command bar back into the game.
Soon I will try posting the direction I am following.
hegemonkhan
12 Apr 2020, 18:22do you need help completely understanding the code or just parts of it confusing you? (aka, do you have some coding knowledge or are you totally new to coding?)
(or just not able to convert it over to doing it in the Game Book version?)
(If you don't want or can't work-with or use the code, I can help you to doing it through the GUI/Editor's buttons, options, tabs, drop-down menus, and etc)
Deckrect
12 Apr 2020, 18:39Here is what I got so far. I am trying to figure out how to make the pop-up work. Note the two last lines are just for checking if the variables make sense. At the start of the game player.effort is set to 6, so when this script happens, it has this value.
get input {
ToInt (result)
if (IsInt (result)) {
switch (result) {
case (result < 0) {
msg ("Try a number from zero to up")
}
case (result > player.effort) {
msg ("You have nor as many Effort Points!")
}
case (IsInt = FALSE) {
msg ("Try a number next time!")
}
}
player.effort = player.effort - result
page2.challenge = result
}
}
msg ("player.effort")
msg ("page2.challenge")
mrangel
12 Apr 2020, 18:57switch
only tests for equality. In this case, you're testing if result
is equal to the expression result < 0
, which will be true or false.
Also, IsInt
returns a numeric value from a string parameter; you're not doing anything with the return value.
I think you want:
if (IsInt (result)) {
bid = ToInt (result)
if (bid < 0) {
DisplayList (Split("Try a number from zero to up"), false)
}
else if (bid > player.effort) {
DisplayList (Split("You have nor as many Effort Points!"), false)
}
else {
player.effort = player.effort - bid
page2.challenge = bid
}
}
else {
DisplayList (Split("Try a number next time!"), false)
}
msg ("player.effort = {player.effort}")
msg ("page2.challenge = {page2.challenge}")
I've not changed your use of DisplayList
, although I changed its parameter to be a list so that it won't cause an error.
hegemonkhan
12 Apr 2020, 19:22the 'ToInt' function returns a value (as an integer data type), so you need to store it into a VARIABLE or use it directly as an argument/parameter for another function, which one source of error for your code
you can change it to this:
result = ToInt (result) // now the 'result' variable's value is an integer value, instead of a string value, for the rest of your code's use
but, you don't want the 'ToInt' before the 'IsInt'... so, you can just remove the 'ToInt' at the top
also, that's not how the 'DisplayList' function works...
and, you're missing the needed 'CDATA' tags too in your code...
but, not a bad attempt at it! coding's not easy to learn, it takes some time!
for the Game Book version, you should be doing something like this:
the 'Pages' are your Objects in the Game Book version
create a 'PageExample' Page
'PageExample' Page Object -> 'Page' Tab -> Page Type: [script] or [script + text]
if using the GUI/Editor: add new script.... (I can help with this, if you need to do it this way)
if you know how to use code, than you can just copy and paste (with some small changes) my code below into it
(delete all of your own code out for this section of scripting, and then copy and paste in my code, with some changes to match up your own stuff, but, make sure you do NOT delete your entire game code!)
change the values as desired
<game name="NAME_OF_GAME">
</game>
<object name="Page1">
<inherit name="editor_object" />
</object>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<attr name="parent" type="object">Page1</attr>
<attr name="effort" type="int">0</attr>
<attr name="bid_value" type="int">0</attr>
</object>
<object name="PageExample">
<inherit name="editor_object" />
<script>
<![CDATA[
msg ("Bid? (type in a value between: 0 and 100")
get input {
if (IsInt (result)) {
bid_input_int = ToInt (result)
if (bid_input_int >= 0 and bid_input_int <= 100) {
if (game.pov.effort >= bid_input_int) {
game.bid_value = bid_input_int
game.pov.effort = game.pov.effort - bid_input_int
} else {
msg ("Error: wrong input, please try again, typing in a number value lesser than or equal to: " + game.pov.effort)
do (PageExample, "script")
}
} else {
msg ("Error: wrong input, please try again, typing in a number value within the inclusive bounds of: 0 to 100")
do (PageExample, "script")
}
} else {
msg ("Error: wrong input, please try again, typing in a number value")
do (PageExample, "script")
}
}
]]>
</script>
</object>
if you still need help, let me know, and I'll get off my lazy bum, and open up quest in Game Book version, and get a working game file for you, to study/examine/play...
PS
oops, accidentally in my previous code I hit the 'v' key, for 'bid', instead of the 'b' key, due to them being next to each other... stupid typos... the bane of programmers/coders, laughs....
mrangel
12 Apr 2020, 19:29and, you're missing the needed 'CDATA' tags too in your code...
No they aren't.
CDATA is XML encoding, it comes immediately before the script. As the OP only posted the part of the script that causes the problem, the CDATA would not be included.
Deckrect
13 Apr 2020, 00:23Gentlemen, I don't understand 80% of the codes you type here. But I used the good and old copy/paste, made minor adjustments and it is working.
HK, It is a Gamebook, but not in gamebook mode. I am using the Text Adventure mode precisely to have more coding resources at hand. Sort of... there is also a kind of precedure in it... But because it is essencially a gamebook, I removed the command bar from the game. Now, I need finding a way to:
A) Remove the command bar from the game and create a popup prompt to take the bidding
OR
B) Add the command bar just for the bidding time and then remove it again, what I think I know how to do.
Creating the pagex.challenge, it gives me a variable I may manipulate to add bonuses and penalties, so it will be great.
Really thank you two! It was a big help!