Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: About Global variables: Such a basic question I can't believe I'm even asking it  (Read 4623 times)

0 Members and 1 Guest are viewing this topic.

deadworm222

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 197
  • Wintermute Army
    • View Profile

This has probably been asked before. But I ask it anyway, because I can't think of a keyword for the search engine.

This question is about variables.

In one room, there's a cupboard. You can open the cupboard with an item.

It would seem logical that when you open the cupboard, it stays open. But no. When you leave the room and come back, the cupboard is closed.

And then I have loads of other problems similar to this one.

How do I have to juggle the variables to make this work? At the moment I use global variables.

P.S. Curves team got two more programmers. Go team, GO!
Logged

Igorrr

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 130
  • Ugh...Ughugh!!!!!!
    • View Profile
    • Struggle For Life And Honour

OK so I answer before the professionals do ;-)

To have the game know that your cupboard is open no matter where you are in the game a global variable would be the best choice.
As in your other post today I would recommend using an arrays for this.
Use something like a global "Flags" or "Area Flags" array  that save the actions you did manipulating your surroundings.
Now of course using a numbered index you have to keep notes somewhere on what index number is referring to, so you could instead indexing like:
Code: [Select]
global Flagsarray("iscupboardopen","isdooropen","characterkilledogre","princessissaved","charakterwokeupwithleftfootfirst","underscores_are_better");
I guess if you write a big game you will have a lot of coding to do...
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site

You can setup the scene to rebeber the activity of the scene nodes (in SpriteEdit, scene properties, "Remember node states"). That way you can have two images, open and closed cupboard, and setting their .Active property you can open/close the cupboard. And the scene will remember their state until next visit.

In your case of having an item hidden inside, you may want to place the closed image over the item so that it's not accessible when the cupboard is closed.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

deadworm222

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 197
  • Wintermute Army
    • View Profile

OK, thanks!
Logged

deadworm222

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 197
  • Wintermute Army
    • View Profile

I got the variables working this way. In the script file of the cabinet object i declared global StateCabinet and then wrote, for example:

Code: [Select]
on "hairpin"
{

if(!StateCabinet.UnLocked)
{
//do stuff
StateCabinet.UnLocked=true;
}


}

BTW, I'm unable to see what code Igorrr has there.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site

BTW, I'm unable to see what code Igorrr has there.

Igorrr's code should look like:

global FlagsArray = new Array("aaa", "bbb", "ccc");
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Igorrr

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 130
  • Ugh...Ughugh!!!!!!
    • View Profile
    • Struggle For Life And Honour

Errr...... ummmmm....yes of course... I meant that  :-\
Logged
 

Page created in 0.121 seconds with 24 queries.