Static ifs on Zinc

Dirac

22710180
Reaction score
147
I've encountered an unexpected problem on using static ifs while coding zinc.
example (returns syntax error)
JASS:
module SomeModule{
	static if(SomeMethod.exists){
		static method A(){
			call SomeMethod();}
	}
	else{
		static method A(){
		//do nothing		
		}
	}
}
It seems that static ifs work fine inside functions, anywhere else return syntax errors, how to fix this issue? Should i stop coding in Zinc?
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Dirac:

1. It seems that static ifs work fine inside functions, anywhere else return syntax errors, how to fix this issue? Should i stop coding in Zinc?

1. You could write your module in vJass and use it inside a zinc struct, and no don't stop coding in zinc [remember it's good for your brain =)].


Edit:

OT:

I don't know how you even thought of stop scripting in zinc just see how good zinc loops are:

JASS:
function f()
{
    integer i;

    BJDebugMsg("digits");
    for (0 <= i < 10) { BJDebugMsg(I2S(i); }
}

vs

function f takes nothing returns nothing
    local integer i
   
    call BJDebugMsg("digits")
    i = 0
    loop
        exitwhen i >= 10
        call BJDebugMsg(I2S(i))
        set i = i + 1
    endloop
endfunction


the for loop is so easy to use and it can't possible be topped.

Although I would've liked it to be called loop and not needing the () and zinc's ";" kinda suck but oh well:

how the "perfect" for me language's loops should look like:
JASS:
void f()
{
    loop 0 <= i < 10 { say(i) } // i implicitly "created"/"allocated";  for typed languages the compiler figures out the size and the signedness (signed/unsigned)
    say(i) // error: i is not visible outside of the loop's header and body for typed languages of course
}
 

Dirac

22710180
Reaction score
147
Can't do the modules in vJass because it uses private variables from the same library.
 

Bribe

vJass errors are legion
Reaction score
67
Stop coding in Zinc, is the solution. Yes the loops and anonymous functions are good but you lose so many features like "readonly", static if's as you've noticed and there have been other bugs with Zinc, I have just forgotten because I haven't coded in it for such a long time.

My advice is to use vJass strictly and let Zinc rot in oblivion.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Dirac:
1. Can't do the modules in vJass because it uses private variables from the same library.

1. Are you sure?:

JASS:
module M

    static if true then
        static method A takes nothing returns nothing
            set my_private_var = 1234
            call SomeMethod()
        endmethod
    else
        static method A takes nothing returns nothing
            //do nothind
        endmethod
    endif
    
endmodule

//! zinc

library L
{
    struct S
    {
        module M; // implement M
        
        private static integer my_private_var;
        static method SomeMethod()
        {
            BJDebugMsg("my_private_var = " + I2S(my_private_var));
        }
        
        static method onInit()
        {
            A(); // prints: my_private_var = 1234
        }
    }
}

//! endzinc


Edit: oh "from the same library" I see, well even better just make them struct members! =) or use some voodo:

JASS:
module M

    static if true then
        static method A takes nothing returns nothing
            set my_private_var = 1234
            set L___var = 5 // big bad voodo
            call SomeMethod()
        endmethod
    else
        static method A takes nothing returns nothing
            //do nothind
        endmethod
    endif
    
endmodule

//! zinc

library L
{
    integer var = 0;
    
    struct S
    {
        module M; // implement M
        
        private static integer my_private_var;

        static method SomeMethod()
        {
            BJDebugMsg("my_private_var = " + I2S(my_private_var));
        }
        
        static method onInit()
        {
            A(); // prints: my_private_var = 1234
        }
    }
}

//! endzinc
 

Dirac

22710180
Reaction score
147
You're missing the point, the module wasn't meant to be implemented inside the same library, its a public module to be implemented in other structs.
In the second example you don't have to type L__var in order to work, L works fine. the var might be private but the module is being implemented into that struct.
What i want is modules outside the library to read variables inside of it, which is impossible to accomplish in zinc since static ifs are clearly broken.
From now on ill just code some stuff on zinc
 

lep

Active Member
Reaction score
8
I've encountered an unexpected problem on using static ifs while coding zinc.
example (returns syntax error)
JASS:
module SomeModule{
	static if(SomeMethod.exists){
		static method A(){
			call SomeMethod();}
	}
	else{
		static method A(){
		//do nothing		
		}
	}
}
[…]
JASS:

module SomeModule{
	static method A(){
            static if(SomeMethod.exists){
			SomeMethod();
            }
	}
}

:confused:
 

Dirac

22710180
Reaction score
147
still no good, i needed the methods to take different arguments depending on the if therefore the if must be outside the method.
Ty all, this has no solution other than not to do it in zinc
 

tooltiperror

Super Moderator
Reaction score
231
Why wouldn't delegates be usable here? I never understood .exists...

JASS:
library DelegateTest
{

keyword Pack;

module Pack
{
	delegate Pack PACK_DEFAULT;
	
	method destructo()
	{
		BJDebugMsg("This struct is being destroyed!");
		this.destroy();
	}
}



struct PACK_DEFAULT
{
	method destroy()
	{
		BJDebugMsg("thistype.destroy does not exist");
	}
}



struct Data
{
	module Pack;

	method remove()
	{
		this.destructo();
	}
}

}
 

Dirac

22710180
Reaction score
147
This would be a special case since the static if dosn't modify the function name, but the arguments it takes.
 

tooltiperror

Super Moderator
Reaction score
231
Could you be a little more specific about what you are trying to achieve?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top