Please help me
How does HasObject work
I'm trying to do a selll inventory system I'm kind of noob and what it does is it cycles until the inventory for a specific item is not in the inventory and I'm having trouble with the While HasObject (Bottle, Player) part and idk why
Hello.
I don't think you don't want HasObject
.
That checks if an object's attribute value points to an object.
http://docs.textadventures.co.uk/quest/functions/hasobject.html
It looks like you only want to check that the player
object is carrying the Bottle
object. In that case, you could use:
if (Bottle.parent = player){
// Do stuff.
}
The most common approach (and the best practice), though, would be:
if (Bottle.parent = game.pov){
// Do stuff
}
This explains why we should try to use game.pov
rather than player
in most cases: http://docs.textadventures.co.uk/quest/quest_code.html#aside-about-player
PS
I avoid while
scripts, unless I'm completely sure that everything in the script will work correctly, inside and out. And then I still avoid them.
If there is a problem, you will end up with an infinite loop, and that usually leads to having to close Quest because it freezes up and starts eating up all your resources.
... and sometimes that's not enough and you have to restart the whole computer.
HasObject
(just for completion)Silly example:
game.foo = Bottle
In that line of code, I set the game
object's "foo" attribute to point to the Bottle
object.
Now, this next line would return true
:
HasObject(game, "foo")
That only tells us the "foo" attribute on the game
object does in fact point to an object (as opposed to pointing to a string, integer, list, etc.).
I'm trying to do a selll inventory system I'm kind of noob and what it does is it cycles until the inventory for a specific item is not in the inventory and I'm having trouble with the While HasObject (Bottle, Player) part and idk why
I think the code you want is while (Got (Bottle)) {
.
However, I'm not sure why you would want to do this. Using a while loop over possession of an item is an unusual thing to do; and if you can show us more of what you're trying to do, there is probably a much simpler way to do it.
It looks like you only want to check that the player object is carrying the Bottle object. In that case, you could use:
That's not ideal, though. Because it only checks if the object is directly inside the player. Sometimes, you want to also include containers (such as if the player has a backpack with the bottle inside).
To include objects in containers, you could use:
if (Contains (game.pov, Bottle)) {
Or, to properly handle both closed containers and invisible objects, you could go for:
if (ListContains (ScopeInventory(), Bottle)) {
(which is what the core Got
function is shorthand for)