Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Print keeps returning object as undefined

I'm currently just trying to create an object using 'edit javascript' and subsequently printing it in the passage but it keeps returning the object as undefined.

In Javascript:
var playerLook = {name: "Project", surname: "Endermis"};

In Passage:
<<print $playerLook.name>>

Comments

  • First. You should always state the story format you're using and its full version, because advice will tend to vary based on that information. Also, please use the code tag when posting code or markup—it's C on the editor bar.

    Since you're attempting to use <<print>>, I'm going to assume that you're using some version of SugarCube.


    When you use a var statement you're declaring a local JavaScript variable, not a story variable.

    To declare/modify a story variable within JavaScript, you need to use the State.variables API. For example:
    State.variables.playerLook = {
    	name    : "Project",
    	surname : "Endermis"
    };
    


    That said, unless you have a good reason to be declaring your story variables within the Story JavaScript, I'd suggest using the StoryInit special passage instead. For example:
    <<set $playerLook to {
    	name    : "Project",
    	surname : "Endermis"
    }>>
    
Sign In or Register to comment.