Global Variables
Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Global Variables  (Read 2451 times)

0 Members and 1 Guest are viewing this topic.

Baron

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 37
    • View Profile
    • Portfolio
Global Variables
« on: January 27, 2009, 07:37:41 PM »

Hello Everyone.

I've read all the posts on Global variables, and the Docs and the Wme book. But I'm still not succeeding in what I need. I struggled with it for a couple of days before posting, I don't want to abuse the good will of the posters here. But I'm really stuck.

I want to make a checklist that the player can view when they want, showing their progress.
I made a scene in my game that is the checklist. As the player goes through the game and collects items a I want a tick to appear on the list, .Ok so I though I would make a global variable for each item that gets collected in the game. When an item is collected the variable is set to true. then if you view the checklist screen a sprite entity for the corresponding item is made active.  I know this should be really easy but some how its not working.

My base.inc
Code: WME Script
  1. #include "scripts\const.inc"
  2.  
  3. global Scene;
  4. global Keyboard;
  5. global actor;
  6. global Score = 0;
  7. global Kannushi;
  8.  

The first scene in the game is Menu.scene and there I initalise the variable
this is the scene_init.script
Code: WME Script
  1. #include "scripts\base.inc"
  2.  
  3. if(Kannushi==null)
  4. {
  5.   Kannushi = false;
  6. }
  7.  
  8. actor.Active = false;
  9. Game.PlaySound("Music\SoftChant.ogg", true);
  10.  

Later when the item is collected It triggers this script
Code: WME Script
  1. on "LeftClick"
  2. {
  3.    Score = Score +1;
  4.    Kannushi = true;
  5.    Game.ChangeScene("scenes\PhotoChecklist\PhotoChecklist.scene");
  6. }
  7.  

This is the scene.init for the checklist scene
Code: WME Script
  1. #include "scripts\base.inc"
  2. actor.Active = false;
  3.  
  4. if (Kannushi == true);
  5. {
  6. var OnNush=Scene.GetNode("PKannushi");
  7.                 OnNush.Active= true;
  8. }

I read in other posts that to use a global in any script you should include
global Kannushi;

but If I do that I get a script error. With this code the tick is constantly displayed even before you trigger the code. Thanks in advance for your help.


« Last Edit: January 28, 2009, 05:09:32 AM by Baron »
Logged

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Global Variables
« Reply #1 on: January 28, 2009, 06:47:07 AM »

How many items do you have?  Do you have more than could appear in one window?

You could use cross outs instead of a checkmark. 

Have a list that has the words for the items and a list for the words for the items crossed out when found. 

You would have to create a window with buttons with text that indicates the item to be found and then a button for each item with the words crossed out in the font (strike through font) and adjust that the strike through button appears by code when the item is found and the normal button is deleted.  I find it very easy to deal with buttons but that may not help you if you have a whole lot of items that can't be shown on one page. 

Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Birdline

  • Supporter
  • Occasional poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 57
    • View Profile
    • Birdline Web Site
Re: Global Variables
« Reply #2 on: January 28, 2009, 08:07:38 AM »

about the global variables
If you have a global variable in the base.inc file (which is included in all scripts)
you must NOT declare it again in no script. You just use it anywhere (give it a value).
(that is why you get the error)
If you have a global variable in a general script, then every time you want to use it you MUST declare it again.

Spyros

Baron

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 37
    • View Profile
    • Portfolio
Re: Global Variables
« Reply #3 on: January 28, 2009, 09:28:07 AM »

Thanks Catacomber and Spyros.

I see, like you said I was declaring the global variable twice. Thanks. I removed the second declarations in the various scripts. I dont get errors ,But unfortunately It still doesnt work for me. I know I am doing something incredibly basic wrong. Well, I will keep bashing away at it and I will be sure to post it when I figure out what I'm doing wrong.

Thanks for the suggestions too, Catacomber.But Im failing at a much more basic level. I can't figure out why my variables still don't work. At the moment its only a small list with about 12 items, and I wanted it to have a nice hand written look, so I'm gonna try and battle on with the sprite entities. As I get better I will be more adventureous. 

cheers everyone.
« Last Edit: January 28, 2009, 09:36:42 AM by Baron »
Logged

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Global Variables
« Reply #4 on: January 28, 2009, 10:14:31 PM »

if (Kannushi == true);

Do you need that ; there?  I don't remember if javascript allows you to do that in a conditional--I thought it was just

if (Kannushi == true)

no ;

The logic of what you're trying to do makes sense---there has to be a way.
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Baron

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 37
    • View Profile
    • Portfolio
Re: Global Variables
« Reply #5 on: January 29, 2009, 05:29:54 AM »

OMG Catacomber god bless you that was it!! I cant believe it, i was pulling my hair out for the last 5 days over that one!!!! I thought i had completely misunderstood variables and there was some special hidden setting or something. what a relief,Thanks again.

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: Global Variables
« Reply #6 on: January 29, 2009, 05:52:48 AM »

You don't know how many times I've done that because I type fast.  :  )))

Welcome to the club.  ; )
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  
 

Page created in 0.633 seconds with 22 queries.