Command does not find object reference of object in inventory - Or can't call verb on other object ?

Selsynn
19 Aug 2018, 00:16

Hello everyone.
I does not understand why something works when I say it with the action verbs and I can't have it work when I passed it at in command

I will explain a bit more. I am working on a deck-building prototype.
The player has a deck object in his inventory.
I associate some action verbs to this object (deck) : "discard all cards" and "draw one card"
When I test typing "discard all cards deck", the script is good and functional. The same with "draw one card deck"

I have wanted to do it as a command "Draw" and its code is quite easy to understand

msg ("First you will need to discard all your cards")
do (deck, "discard all cards")
msg ("Now you can draw new cards")
do (deck, "draw one card")

But it does not work.

First you will need to discard all your cards
Error running script: Object reference not set to an instance of an object.
Now you can draw new cards
Error running script: Object reference not set to an instance of an object.

I think it is because it does not know deck. But deck is in the inventory.
I tried to add 'inventory' in the scope to no new result

I think it is maybe not possible to call verb on object. Is it possible ?
Or the error is somewhere else and i don't see it ?

Thanks for your help, it's bugging me.


mrangel
19 Aug 2018, 07:52

Is the name of the deck actually "deck"? Remember that when the player types a command, they must type the object's alias, but in the script you always use the object's name.

A second thought is that Quest maintains a verbs list which maps verb names onto attribute names. If the verb is named "discard all cards", it's possible that the corresponding script attribute is named "discardallcards" without the spaces, and that's what you might need to put in the do() statement.


Selsynn
19 Aug 2018, 13:10

Thanks for your reply !
Yes it is "deck" the name of the object. I didn't knew we could not use the name of the alias, good to know.
But I just tested with no space between the words of the verb and it works !

Thank you ! Now I will know to call without space the verb name.


mrangel
19 Aug 2018, 13:31

Sometimes it can be hard to guess what the property name is.

If you look at the game in full code view, you will probably find a bit that looks like this:

  <verb>
    <property>discardallcards</property>
    <pattern>discard all cards</pattern>
    <defaultexpression>"You can't discard all cards " + object.article + "."</defaultexpression>
  </verb>

If I remember correctly, the <property> line is the attribute name that you need if you want to call it using do(), the <pattern> line is what the player needs to type to use the verb manually, and the <defaultexpression> line is what the player sees if they try to use the verb on the wrong object.