Error compiling expression: Unknown object or variable

bellingshausen
23 Jun 2018, 21:00

Hello! New quest user here. Taking a crack at making a simple text adventure game, and I need a bit of help understanding something.

The situation I've set up is having an NPC dealing the player 3 tarot cards, then flipping them over and revealing each one with the following function.

<function name="tarotchoice">
msg ("The man lays his hand on the leftmost of the three cards, and in one fluid motion flips it over.")
wait {
  card1 = PickOneChild (tarotdeck)
  firstcard.alias = card1
  card1pic
  msg ("Before you on the table, a stylized tarot card with \'" + GetDisplayName(card1) + "\' written on the bottom.")
  MoveObject (card1, boundcards)
}

This works fine, and when the 'card1pic' function is called in the middle there, it also works fine and displays the randomly selected card's picture.

<function name="card1pic">
if (firstcard.alias = Death) {
  picture ("Death.jpg")
}

(there are like 20 more if/then's for the rest of the cards).

The thing is, I had some trouble getting it to do that. I'm on desktop, and for a while I was trying to do everything in code view. And when I typed up the list of card pictures in code view, it would keep giving me

"Error compiling expression 'firstcard.alias = (((card)))': Unknown object or variable '(((card)))'".

But when I went back in the non-code interface and added script "if (object attribute equals) Object (object) (firstcard) Attribute (alias) = (((card)))" by clicking on the little blue down arrow and selecting which card I wanted, it worked without a hitch. I went back and did it for every single card except Wheel Of Fortune (which I typed in), and that's the only one that isn't working now (for the sake of error reproduction).

Am I going to have to keep editing this in the non-code thing? Is something big flying over my head here? Is there something I should be doing that I'm not doing to make this run smoothly?

Sorry for the long post. Thanks for any help!


mrangel
23 Jun 2018, 22:47

Are you sure that you typed the name of the card exactly right, including any spaces and capital letters?

If you share the game, somebody else could take a look at the code and see if they can find the problem. As it is, we're only guessing.


bellingshausen
24 Jun 2018, 01:39

I'll do that. Thanks!


Dcoder
24 Jun 2018, 02:07

Normally, the .alias attribute is a string attribute (in quotes). Your code seems to be using firstcard.alias as an object attribute (no quotes). That doesn't sound quite right...

Upon further reflection...
So you are using .alias as an object attribute, but that might be confusing Quest somewhere since .alias is normally a string attribute (Quest can be touchy about using standardized variables like "game", "object", "type", etc. differently from their original intent). I would use something like game.firstcard or player.firstcard instead of firstcard.alias.

Actually, I don't see why you need both a card1 variable and a firstcard.alias variable. Why not just use a single variable like player.card1 or something?


bellingshausen
24 Jun 2018, 15:18

I was trying to fix the issue first by going on the forums and tryna find a sample of code that I might be able to use, and the first thing I found was something that used the little stepping-stone 'card1' thing. It worked, but it didn't fix the problem I was struggling with, and I think I just forgot to take it out. Now, though, I know why I should take it out. Thank you!


mrangel
24 Jun 2018, 15:32

I'm curious; are you going to add functions card2pic, card3pic and so on? Or do you only want to display the picture for the first card?

This seems like a situation when a function parameter would save a lot of work later.

The function would then be…

<function name="tarotchoice">
  msg ("The man lays his hand on the leftmost of the three cards, and in one fluid motion flips it over.")
  wait {
    card = PickOneChild (tarotdeck)
    cardpic(card)
    msg ("Before you on the table, a stylized tarot card with '" + GetDisplayName(card) + "' written on the bottom.")
    MoveObject (card, boundcards)
  }
</function>

<function name="cardpic" parameters="card">
  if (card.alias = Death) {
    picture ("Death.jpg")
  }

[···]

</function>

Also, if the picture filenames are all the card's name with ".jpg" added to the end, you could remove all the else if clauses, and shorten that to:

<function name="cardpic" parameters="card">
  picture (card.name + ".jpg")
</function>

bellingshausen
24 Jun 2018, 17:24

Actually, I've already been working on something like that-- I just didn't mention it in this post. Your suggestion of making a (card.name + ".jpg") didn't even cross my mind, though.

Once I finish putting together the code for the first card choice so that it isn't straight up unfinished, I'll share the game in a different post. I have a lot more questions on a lot more things (mostly concerning optimization). Thanks again for the advice!