Howdy, Stranger!

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

Help! How do you call functions in Snowman!

Hi!
I'm using JavaScript to manage many variables in my game. Now, I want to add a simple number that can be held and added to throughout the game. So, for example, When you click a link or button, it will add or subtract 1 from the value. Here is my work.
<%
function rStatus(rank) {
      return rank + 1; //Adds 1 to the initial value//
}
rStatus(0) //This is the inital value//
%>
Then later, in my story I want to call back to this number and say something along the lines of "Your rank is rank". Here is my code for that.
<%
print("Your rank is "+rank);
%>
Now for some reason no matter how I run it, it will usually bring up and error that says "sStatus or rank is undefined"

Maybe I'm missing something? Is my code wrong? Please help!

Comments

  • Snowman 2 assumes that the Author has an understanding of how to program using HTML, CSS, and Javascript. If you are not a programmer then you may find it easier starting with one of the other Story Formats.

    Each of your three questions so far (Q1 and Q2) are all about the same issue, and that issue is Javascript (Variable) Scope.

    In Q1's case you were trying to reference a variable that was defined in one local scope from another local scope, the solution was to define those variables on a special variable that Snowman passes to all passages shown to the Reader.

    In Q2 and this questions case you are trying to reference a variable that is defined as a parameter to a function defined in one local scope with another local scope, which fails for two reasons:

    a. Different local scope.
    b. You can't externally reference a parameter outside the function it is defined in.

    If you really wan to keep using Snowman then I suggest you read the Referencing code between rooms in Snowman thread which contains an example of how to use the s special variable and an example of how to define your custom functions in a way that allows them to be used in any passage.
Sign In or Register to comment.