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: Strange Problem with duplicated variables  (Read 2180 times)

0 Members and 1 Guest are viewing this topic.

IvanErtlov

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 12
    • View Profile
Strange Problem with duplicated variables
« on: July 17, 2010, 12:29:39 PM »

I´ve written some code that selects a trading card from a stack, the code looks like that:

var mycard = Random(1,10);

var foecard = Random(1,10);


if (foecard==1)
   {
   var fcardAT = 13;   
   var fcardDF = 11;
   var fcardCO = 12;
   var fcardINT = 9;
   var fcardSP = 9;
   var fcardST = 10;
   var fsprite = "sprites\cards\card1.sprite";
   }

if (foecard==2)
   {
   var fcardAT = 12;
   var fcardDF = 6;
   var fcardCO = 8;
   var fcardINT = 9;
   var fcardSP = 11;
   var fcardST = 8;
   var fsprite = "sprites\cards\card2.sprite";
   }

if (foecard==3)
   {
   var fcardAT = 11;
   var fcardDF = 13;
   var fcardCO = 12;
   var fcardINT = 10;
   var fcardSP = 8;
   var fcardST = 12;
   var fsprite = "sprites\cards\card3.sprite";
   }


(and so on)

So basically the variables for the card values should only be set according to the right card. However, I get these error messages:

13:07: Compiling script 'scenes\battlefield\scr\scene_init.script'...
13:07:   Error@line 55: Duplicate declaration of variable 'fcardAT'
13:07: Compiling script 'scenes\battlefield\scr\scene_init.script'...
13:07:   Error@line 56: Duplicate declaration of variable 'fcardDF'
13:07: Compiling script 'scenes\battlefield\scr\scene_init.script'...



Looks like the "if" is ignored and all variable sets are executed!

Anyone a clue?
Logged

IvanErtlov

  • Supporter
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 12
    • View Profile
Re: Strange Problem with duplicated variables
« Reply #1 on: July 17, 2010, 01:04:46 PM »

SOLVED

(with some logic)
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: Strange Problem with duplicated variables
« Reply #2 on: July 17, 2010, 02:07:22 PM »

ouch. How about some nesting?

Code: WME Script
  1.  
  2. var fcard;
  3.  
  4.  
  5. switch (foecard)
  6. {
  7.    case 1:
  8.       fcard.AT = 10;
  9.       fcard.INT = 15;
  10.      /// etc.
  11.     break;
  12.  
  13.    case 2:
  14.       fcard.AT = 12;
  15.       fcard.INT = 11;
  16.      /// etc.
  17.     break;
  18. }
  19.  

Your code scared me. :)
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet
 

Page created in 0.031 seconds with 21 queries.