0 votes
by (2.4k points)
retagged by

Hi everybody,

I'm having a problem with my code where an object is aparently not being declared. First I'm using this code to declare two different objects:

<<set $inv_cinquedea to {
  id: "weapon.cinquedea" ,
  type: "weapon",
  subtype: "dagger",
  cost: 100,
  name_es: "Daga cinquedea",
  name_en: "Cinquedea dagger",
  desc_es: "Una daga de hoja ancha, más pensada como un accesorio que como un arma real.",
  desc_en: "A wide blade dagger, more used as an accessory than as a real weapon."

<<set $inv_dimaedroClothes to {
  id: "clothes.dimaedro",
  type: "clothes",
  subtype: "elegant",
  cost: 200,
  name_es: "Ropajes elegantes de Dimaedro",
  name_en: "Elegant clothes from Dimaedro",
  desc_es: "Un traje considerando elegante según la moda de Dimaedro. No ofrece protección alguna.",
  desc_en: "Clothes considered elegant according to Dimaedro fashion. It does not offer any protection."

And then I'm just trying to access them like this:

<<print $inv_cinquedea.name_en>>
<<print $inv_dimaedroClothes.name_en>>

The objects declaration gives no errors, but when trying to print them only the first one ($inv_cinquedea) works properly, while the second one ($inv_dimaedroClothes) gives me this error message:

Error: <<print>>: bad evaluation: State.variables.inv_dimaedroClothes is undefined

<<print $inv_dimaedroClothes.name_en>>

Does anybody know where the problem is? I'm sure it's going to be an stupid error like "you forgot to put a comma there", but I've been trying to fix it for hours now and I can't see where the problem is. >.<



1 Answer

0 votes
by (44.7k points)
selected by
Best answer

There's nothing wrong with the code you have above, so it has to either be A) you're loading an old save where that value wasn't set, B) there's something in your other code which isn't included above which is breaking things, or C) there's some "invisible character" in your code which is causing the problem and it didn't get copied to here.

You could try running in "Test" mode to see if that variable is set using the "Debug" window (bottom-right).

Another thing to try doing is, right after declaring $inv_dimaedroClothes, put the following line to verify that it was set at that point:

<<run alert($inv_dimaedroClothes.name_en)>>

If the pop-up alert works at that point, then you know it was set correctly.  Then you just need to trace down where it got undefined.

If it doesn't pop-up an alert, then you know the value wasn't set.

Finally, if it's an "invisible character", just copy and paste the above code over the matching code, and that should fix it.

I'm guessing you're running into problem A (I've done that myself), but those solutions should help if you ever run into the other two options.

Hope that helps!  :-)

by (2.4k points)
Yep, it was the problem A...

It was not exactly an old save, but I was declaring the variables in a passage loaded in StoryInit and I must have forgotten to restart the game onve before reloading the passage where I was testing it.