Drink from bottle
smh479
16 Jul 2020, 16:00I need help. I made a watersource that fills a bottle with water. That worked but when I do the code (from the textadventures guide) to drink from the bottle it does not work. Whst can I do?
mrangel
16 Jul 2020, 16:11What do you mean it doesn't work?
To understand what problem you are having, you need to show us the relevant code (or a link to your game), the command the player enters, what you expect to happen, and what actually happens. If it gives an error message, tell us what that message is.
smh479
16 Jul 2020, 17:29hi mrangel
I made a sink and a bottle with the cods from http://docs.textadventures.co.uk/quest/handling_water.html
Like I said I can make the sink switch on and off the water. So I can fill the bottle with water.
On the switchable side of the sink I did this:
this.parent.watersource = true
this.parent.watersource = false
I made a attribute on the bottle with full and capacity 0 and 10.
Than I made a verb "fill":
if (this.full = this.capacity) {
msg ("It is already full.")
}
else if (not GetBoolean(game.pov.parent, "watersource")) {
msg ("No water here.")
}
else {
msg ("You fill it.")
this.full = this.capacity
}
that worked perfectly I can switch the sink on and off and I can fill the bottle.
my problem is this one:
if (this.full = 0) {
msg ("It is empty.")
}
else {
msg ("You take a drink from it.")
this.full = this.full - 1
}
I should make a verb "drink from" but it does not work.
It says:
drink from bottle
Error running script: Error compiling expression 'this.full = 0': CompareElement: Operation 'Equal' is not defined for types 'String' and 'Int32'
Thank you for your help!
smh479
16 Jul 2020, 17:30 <inherit name="editor_object" />
<inherit name="switchable" />
<feature_switchable />
<displayverbs type="stringlist">
<value>Look at</value>
<value>Switch on</value>
<value>Switch off</value>
</displayverbs>
<inventoryverbs type="stringlist">
<value>Look at</value>
<value>Use</value>
<value>Switch on</value>
<value>Switch off</value>
</inventoryverbs>
<onswitchon type="script">
this.parent.watersource = true
</onswitchon>
<onswitchoff type="script">
this.parent.watersource = false
</onswitchoff>
</object>
<object name="bottle">
<inherit name="editor_object" />
<full>10</full>
<capacity>0</capacity>
<inventoryverbs type="stringlist">
<value>Look at</value>
<value>Drop</value>
</inventoryverbs>
<feature_usegive />
<fill type="script">
if (this.full = this.capacity) {
msg ("It is already full.")
}
else if (not GetBoolean(game.pov.parent, "watersource")) {
msg ("No water here.")
}
else {
msg ("You fill it.")
this.full = this.capacity
}
</fill>
<use type="script">
do (this, "drinkfrom")
</use>
<drinkfrom type="script">
if (this.full = 0) {
msg ("It is empty.")
}
else {
msg ("You take a drink from it.")
this.full = this.full - 1
}
</drinkfrom>
</object>
</object>```
smh479
16 Jul 2020, 17:31How can I post the whole code of my game? Its not showing.. - it worked now (look above)
smh479
16 Jul 2020, 18:33Please someone help me :)
mrangel
16 Jul 2020, 19:01Your problem is the attribute types.
The capacity of your bottle is the string 10
. That is, a sequence of text containing the character 1
and the character 0
.
When you fill the bottle, it sets the full
attribute to the same as capacity
- the string 10
.
So in your drink command, the line:
if (this.full = 0) {
compares the string 10
to the number 0.
Quest only allows you to compare two things of the same type. You can check if two strings are the same, or you can check if two numbers are the same. But you get an error if you try to check if a string is equal to a number.
When you created the attributes, you need to set both full
and capacity
to be numeric types. This means that the type should be "integer" (not "string").
I'm not sure how this looks in the editor, as I've only used the web editor (which doesn't have the Attributes tab) - but there should be a way to change the type of each attribute.
When you've got it set up correctly, that part of the code view should look like:
<object name="bottle">
<inherit name="editor_object" />
<full type="int">10</full>
<capacity type="int">10</capacity>
Other than that, I can't see any other issues with the code.
I'm not so good at explaining stuff, and I know some people find this hard to understand. I think I've said it a few different ways, so I hope one of them makes sense.
smh479
16 Jul 2020, 19:40Thank you very much. I think I understand. I try it!
smh479
16 Jul 2020, 20:03It works! Thank you so much!
smh479
16 Jul 2020, 20:15one problem left, the bottle does not go empty...

DarkLizerd
17 Jul 2020, 00:03To test what's happening...
Try this:
(Your code bit)
msg ("You take a drink from it.")
this.full = this.full - 1
Change to:
msg ("You take a drink from it.")
this.full = this.full - 1
msg("There are " + this.full + " drinks left.")
And watch what happens.

Doctor Agon
17 Jul 2020, 01:11Check the values of the two intergers 'full'
and 'capacity'
, are you sure they are the correct values.
Initially, 'full'
should be set to 0
,
and 'capacaity'
should be set to 10
Looking at the code you posted above, you seem to have capacity set at 0
smh479
17 Jul 2020, 13:19thank you!

Doctor Agon
17 Jul 2020, 21:53When I've used this, I've also made a 'water object' in the room as well, which I initially set to invisible, then make visible or invisible, depending on whether the tap is on or off.
I also put a 'look at' description on the tap as follows
The tap is turned {if bathroom.watersource:on, {object:water} gushes out into the bath}{if not bathroom.watersource:off}.
On the 'water object', for 'take', I set it to run a script, as follows
if (not GetBoolean(game.pov.parent, "watersource")) {
msg ("There is no water here.")
}
else {
if (Got(bottle)) {
OutputTextNoBr ("Using the {object:bottle}: ")
do (bottle, "fill")
}
else {
msg ("You try to pick up the water, but it unsurprisingly slips through your fingers.")
}
}
smh479
18 Jul 2020, 15:38thank you all so much