Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Basic question about variables  (Read 2436 times)

0 Members and 1 Guest are viewing this topic.

Mikael

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 127
    • View Profile
    • MDNA Games
Basic question about variables
« on: March 13, 2007, 06:40:37 PM »

OK. I'm just trying to learn how to use variables. What I'm trying to do is extremely basic, and I'm sure that I will sound like a complete fool, but here goes:

(I have been searching the documentation and forum for hours, but haven't found an answer).

Let's say that I have a switch that opens a door, and that I use a global variable called "dooropen". If I have clicked the switch, and then click the door, the door will open and take us to the next scene, and if I have not clicked switch, we will just hear the sound of the door handle.

Let's say that clicking the switch sets the variable "dooropen" to "1". Am I right in assuming that I just use the following code in the region entity for the switch?
global dooropen = 1;

OK, then there is the question about what code to use for the region entity for the door. I've tried every possible combination of something like this:

global dooropen;
if(dooropen = 1)
on "LeftClick"
{
  Game.ChangeScene("scenes\xxx\xxx.scene");
}
else
{
  Game.PlayMusicChannel(1, "sounds\xxx.ogg", false);
}
 

(I'm sure that there are better ways to play the sound than through a music channel, I just haven't gotten that far yet).


That's it. As I said, extremely basic, but once I can grasp this, I think I can master the method of variables.

Thanks in advance!
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Basic question about variables
« Reply #1 on: March 13, 2007, 06:54:08 PM »

The event handlers (on "something" ...) are "top-level" statements, you can't enclose them in some other statements. You need to put the condition inside, like this:

Code: [Select]
on "LeftClick"
{
  if(dooropen==1) Game.ChangeScene("scenes\xxx\xxx.scene");
  else Game.PlayMusicChannel(1, "sounds\xxx.ogg", false);
}

In other words, first we need to tell the script what events we want it to react to (LeftClick), and once the LeftClick arrives, we decide what to do.

Also notice the == operator, not =.
"=" is used for assignment, "==" is used for comparison.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mikael

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 127
    • View Profile
    • MDNA Games
Re: Basic question about variables
« Reply #2 on: March 13, 2007, 07:45:16 PM »

... and now it works!

Thanks a million for another relevant and FAST reply. My wife and I have been making these 1st person games: http://www.mdna-games.com/ for some time now, using some other engines. We decided that it's time to look for a new engine (mostly due to the fact that the games created with our current engine are Vista incompatible). After doing an extensive search there was no doubt that WME is the most powerful one (although it has a steep learning curve). I've never been a friend of coding every hotspot, but I guess that it will have to change now.

However, I did hear that the people in the forum and the developer support was great, but I never even imagined that it was this fast, friendly, and to-the-point.

Thanks again, and now back to my own little demo game ...

Regards,

Mikael
Logged
 

Page created in 0.036 seconds with 23 queries.