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: Warning message question  (Read 2487 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
Warning message question
« on: April 28, 2007, 02:50:59 AM »

I'm trying out a script that makes entities appear and disappear depending on the positions of switches. Everything works exactly as planned, except that I get this error log message: "Warning: variable 'ent_handle_2_down' is inaccessible in the current block. Consider changing the script."

I've tried the scene back and forth, and it no doubt works perfectly, despite the message. I can not see how I could mess around with the "inaccessible" variable without causing major dysfunction.

The code looks like this (it's probably idiotic):

Code: [Select]
global handles_down;

on "LeftClick"

{
  if(handles_down==1)
  {
  global handle_2_down = 1;
  var ent_handle_2_down = Scene.GetNode("handle_2_down");
  if(handle_2_down==1) ent_handle_2_down.Active = true;
  handles_down = 2;
  }
  else
  {
  handle_2_down = 1;
  ent_handle_2_down = Scene.GetNode("handle_2_down");
  if(handle_2_down==1) ent_handle_2_down.Active = true;
  handles_down = 0;
}}

The warning refers to the 3rd line from the bottom.

Thanks,

Mikael
« Last Edit: April 28, 2007, 03:26:58 AM by Mikael »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Warning message question
« Reply #1 on: April 28, 2007, 09:06:02 AM »

The script compiler is actually asking you to move the 'handle_2_down' declaration outside the 'if' block, so that both the if-else branches can "see" it. Like this:


Code: [Select]
global handles_down;
global handle_2_down;

on "LeftClick"

{
  if(handles_down==1)
  {
    handle_2_down = 1;
    var ent_handle_2_down = Scene.GetNode("handle_2_down");
    if(handle_2_down==1) ent_handle_2_down.Active = true;
    handles_down = 2;
  }
  else
  {
    handle_2_down = 1;
    ent_handle_2_down = Scene.GetNode("handle_2_down");
    if(handle_2_down==1) ent_handle_2_down.Active = true;
    handles_down = 0;
  }
}

And now it'll probably complain about the 'ent_handle_2_down' local variable for the same reason :)

It's not a big deal, but under certain conditions it can save you from some hard to find mistakes.
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: Warning message question
« Reply #2 on: April 28, 2007, 09:46:57 AM »

I moved both declarations outside of the "if" block, and the log stopped bugging me. Thanks! I would never have figured that out for myself.

Mikael
Logged
 

Page created in 0.037 seconds with 23 queries.