Main      Site Guide    
Message Forum
Re: SMASH - newbie question
Posted By: Sam, on host 24.34.46.67
Date: Monday, July 6, 2009, at 20:39:32
In Reply To: SMASH - newbie question posted by Eniliad on Monday, July 6, 2009, at 19:15:17:

> Hello, I'm trying to get into smash, I'm interested in making a game. I have a silly newbie question: How can I access/change variables in other .sma files? In this example, I have a lever which opens a sealed door. The door should be passable if the lever has been pulled. How can I do this? Or am I required to use global variables?

You need to use global variables if you want to *modify* the value of a variable from more than one location. However, state (local) variables can be *checked* from other locations even though they can only be set from one.

As an example, let's say you have room1 and room2. Room1 has the lever, but room2 needs to check it.

room1.sma excerpt:

* 1 Pull the lever.
____ s lever = !lever

room2.sma excerpt:

^ 1 Go through the door.
____ c room1.lever = 1
________ g nextroom
____ C
________ p The door is sealed shut!

Of course the underscores shouldn't be in your code; I just use them here to indent properly. But this is the idea. The syntax "location.variablename" can be used in expressions when you're trying to reference a variable from some location other than the current one.

Replies To This Message

Post a Reply

RinkChat Username:
Password:
Email: (optional)
Subject:
Message:
Link URL: (optional)
Link Title: (optional)

Make sure you read our message forum policy before posting.