Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: Global variable problem  (Read 4362 times)

0 Members and 1 Guest are viewing this topic.

wisemanxxx

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 10
    • View Profile
Global variable problem
« on: May 17, 2010, 12:27:31 PM »

I want some global values like score, time, player's name etc.
I put a global variable in base.inc (I tried const.inc and game.script too).
Anywhere in game I change this value and use it with a textbox.
But textbox always shows null.Only it works when I give value in same script.
 
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Global variable problem
« Reply #1 on: May 17, 2010, 04:07:39 PM »

base.inc serves for common declarations (shorthand).

Base.inc
Code: WME Script
  1. global score;
  2.  

Test_script1.script
Code: WME Script
  1. score = 10;
  2.  

Test_script2.script
Code: WME Script
  1. Game.Msg(score);
  2.  
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

ugo

  • Вредная ворона
  • Regular poster
  • ***
  • Karma: 2
  • Offline Offline
  • Gender: Male
  • Posts: 156
  • Делаю кве
    • View Profile
    • Хранители традиций УниВанга
Re: Global variable problem
« Reply #2 on: November 10, 2010, 11:43:10 AM »

But, if this script again to launched, variable again to assumes value 10.

What should i do?
Logged

shuin

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 51
    • View Profile
Re: Global variable problem
« Reply #3 on: November 10, 2010, 06:45:19 PM »

Did you initialize the global in the include file? You shouldn't do that
Logged
Untitled project status: production

ugo

  • Вредная ворона
  • Regular poster
  • ***
  • Karma: 2
  • Offline Offline
  • Gender: Male
  • Posts: 156
  • Делаю кве
    • View Profile
    • Хранители традиций УниВанга
Re: Global variable problem
« Reply #4 on: November 11, 2010, 05:14:35 AM »

Do not sure, I`m understand all correct.

"include file" is this - "Test_script1.script" or "Test_script2.script" or some else?
How can i initialize the global?

Whenever "Test_script1.script" is run,  variable again to assumes value 10.
But I need saved new value. For example 11.

Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Global variable problem
« Reply #5 on: November 11, 2010, 07:34:08 AM »

If you insist on setting the value in the included file, you can check if the variable already has some value.

Code: WME Script
  1. global someVar;
  2. if (someVar == null) someVar = 10;
  3.  

This will only set the value the first time.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

ugo

  • Вредная ворона
  • Regular poster
  • ***
  • Karma: 2
  • Offline Offline
  • Gender: Male
  • Posts: 156
  • Делаю кве
    • View Profile
    • Хранители традиций УниВанга
Re: Global variable problem
« Reply #6 on: November 11, 2010, 07:58:56 AM »

Thanks.
Logged
 

Page created in 0.054 seconds with 22 queries.