• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] WTF?! Strange encounter!

Status
Not open for further replies.
Level 8
Joined
Jun 28, 2008
Messages
356
JASS:
globals

    //... some variables ...
    integer t = 0
    
endglobals

//... some code ...

function OnlyEnemies takes nothing returns boolean

    return (player_team[GetPlayerId(GetOwningPlayer(GetFilterUnit()))] != t)

endfunction

//... some more code ...

This code above saves fine with the map, but when I press the Test button - it leads me to the game menu, instead of the map load screen. However, a small variable name change like this one below fixes everything:

JASS:
globals

    //... some variables ...
    integer whichteam = 0
    
endglobals

//... some code ...

function OnlyEnemies takes nothing returns boolean

    return (player_team[GetPlayerId(GetOwningPlayer(GetFilterUnit()))] != whichteam)

endfunction

//... some more code ...

WTF?! Someone plz EXPLAIN THIS BULLSHIT Q_Q I'm pretty sure I'm not having any other global/local variables with the name 't'. What is this?
 
Level 8
Joined
Jun 28, 2008
Messages
356
No error pops up. Ever. It just "compiles" fine as it should. But when I click 'test map' and oops game menu o_O. I'm gonna test now if this problem is caused by other variables names that Dr. Boom suggested.

P.S. Self-speaking variable names is like, when you read the name of it, and you know the whole reason of the code. Like this:

This_Variable_Holds_The_Unit_That_Casts_The_Ability_In_This_Trigger

^--- That's self-speaking.

spellCasterUnit

^--- Sortoff

scu

^--- Bullshit.
 
Level 8
Joined
Jun 28, 2008
Messages
356
Nope, if I have a local trigger variable named "t" (which I never do, I name them 'trig') it is supposed to shadow the global one and use the local, also it may give a warning about an argument shadowing a global (does vJASS do that?), but even if it doesn't CreateTrigger() returns a variable of type 'trigger' which is not compatible with 'integer' so yeah...

But I double checked the code, there are no variables named 't' ANYWHERE in ANY trigger. =/
 
Level 8
Joined
Jun 28, 2008
Messages
356
OK, I finally conquered my lazyness and made some researches. Here comes kraken:

Works perfectly.
JASS:
globals
    integer kur = 0
endglobals

function Racism takes nothing returns boolean
    
    return 5 == kur

endfunction

Works also perfectly.
JASS:
globals
    integer kur = 0
endglobals

function HellYeah takes nothing returns nothing
    local integer kur
    set kur = 5
    call BJDebugMsg("um lol wut?")
endfunction

function Racism takes nothing returns boolean
    
    return 5 == kur

endfunction

Just that, no code, works perfectly.
JASS:
globals
    integer t = 0
endglobals

Oh noez! Game menu :[
JASS:
globals
    integer t = 0
endglobals

function Racism takes nothing returns boolean
    
    return 5 == t

endfunction

Compile error: Cannot convert timer to integer on line 'timer t'
JASS:
globals
    timer t = 0
endglobals

function Racism takes nothing returns boolean
    
    return CreateTimer() == t

endfunction

Bullshit continues, as this WORKS infact without a problem
JASS:
globals
    real t = 0
endglobals

This leads to the game menu...
JASS:
globals
    real t = 0
endglobals

function Racism takes nothing returns boolean
    
    return 3.14 == t

endfunction

This doesn't work :O:O:O
JASS:
globals
    integer u = 0
endglobals

function Racism takes nothing returns boolean
    
    return 5 == u

endfunction

:O Oh, mighty Dr. Boom, your theory is right!!!!111!!one!!11!!!

EDIT:

This thing also works
JASS:
function Racism takes nothing returns boolean
    
    local integer u = 0
    local timer t
    return 5 == u

endfunction

Btw, I'm not using any scopes or libraries, I can't make it private. Even if I did, declaring a variable named 'something' inside a library would rename it to 'mylibrary__something' when converting to simple JASS, no?
 
Level 8
Joined
Jun 28, 2008
Messages
356
Your war3map.j file uses local variables named t, u, e and others.

Blizzard recently added a feature (cough, bug) which prevents shadowing globals with local variables, so the map crashes if you try to do that.

There is your problem. vJass has the private keyword for a reason.

This thread is solved.

Not just yet. As you saw in my previous post (I suppose you did), I attempted to shadow globals with locals and it worked just fine.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
You really shouldn't leave it up to chance whether or not your code logically makes sense. If you've got references to a variable (could be an integer, or any other type) named T and it appears in dozens of places throughout your code (one global, many locals) then you're bound to run into some logic problems. You're relying on modular error-checking to ensure the proper compilation of your code. It is easier to be completely unambiguous.

JASS:
scope WhateverYouWereTryingToDo


globals
    private integer t = 0
endglobals


function YouAreARacist takes nothing returns boolean
    return 5 == t
endfunction


endscope

This works fine, regardless of whether or not you're trying to shadow globals. There is no reason to be ambiguous.

Worth mentioning, none of the code you've posted above causes my test map to load the main screen. They all compile fine and when test map is used they open the map properly as in any case. Do not create work for yourself by doing things in a difficult manner. If you had used proper encapsulation (rather than ignoring names and trying to be clever with shadowing globals) you wouldn't have run into this problem, and many others that you may run into if you try to do things your own way.
 
Level 8
Joined
Jun 28, 2008
Messages
356
You really shouldn't leave it up to chance whether or not your code logically makes sense. If you've got references to a variable (could be an integer, or any other type) named T and it appears in dozens of places throughout your code (one global, many locals) then you're bound to run into some logic problems. You're relying on modular error-checking to ensure the proper compilation of your code. It is easier to be completely unambiguous.

JASS:
scope WhateverYouWereTryingToDo


globals
    private integer t = 0
endglobals


function YouAreARacist takes nothing returns boolean
    return 5 == t
endfunction


endscope

This works fine, regardless of whether or not you're trying to shadow globals. There is no reason to be ambiguous.

Worth mentioning, none of the code you've posted above causes my test map to load the main screen. They all compile fine and when test map is used they open the map properly as in any case. Do not create work for yourself by doing things in a difficult manner. If you had used proper encapsulation (rather than ignoring names and trying to be clever with shadowing globals) you wouldn't have run into this problem, and many others that you may run into if you try to do things your own way.

Lol, Ok, I'm not having a big problem or anything, I avoided it easy, don't worry about that, I was just wondering why did that happen and now I know. :] That's it. Thanks everyone for trying to help!
 
Status
Not open for further replies.
Top