wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Warcraft III Modding > Developer's Corner > Warcraft Editing Tools
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 10-13-2009, 02:41 PM   #2641
Zoxc
( ~)>
 
Zoxc's Avatar


Respected User
 
Join Date: Feb 2005
Posts: 959

Submissions (9)

Zoxc is just really nice (312)Zoxc is just really nice (312)Zoxc is just really nice (312)

Default

I was hoping for a second I would be able to do stuff like this:

Hidden information:
(Example of a wierd language with Ruby like syntax)
Code:
class Handle
        public
                static constant MinId: Integer = 0x100000
                
                method id: Integer
                        GetHandleId(self)
                end
end
 
class Group < Agent
        private
                static flag: Boolean = false
                static refr: Group = nil
                
                # Assorted constants
                static constant MaxHandleCount: Integer = 408000
 
                # Arrays and counter for the group stack
                static groups: Group[]
                static status: Integer[MaxHandleCount]
                static count: Integer     
                
                # ForGroup wrapper
                static each_callback: ->(Unit)
                
                function each_forgroup
                        each_callback(GetEnumUnit())
                end
                
                function add_ex
                        if flag
                                GroupClear(refr)
                                set flag = false
                        end
                        
                        GroupAddUnit(refr, GetEnumUnit())
                end
                
        public
                function allocate: Group
                        if count == 0 then
                                groups[0] = CreateGroup()
                        else
                                count =- 1
                        end
                        
                        status[groups[count].id - Handle::MinId] = 1
                        
                        return groups[count]
                end
                
                method destroy
                        stat: Integer = status[self.id - Handle::MinId]
                        
                        case
                                when self == nil
                                        debug("Error: Null groups cannot be released")
                                        
                                when stat == 0
                                        debug("Error: Group not part of stack")
                                        
                                when stat == 2
                                        debug("Error: Groups cannot be multiply released")
                                        
                                when count == 8191
                                        debug("Error: Max groups achieved, destroying group")
                                        DestroyGroup(self)      
                        end
                        
                        GroupClear(self)
                        groups[count] = self
                        count += 1
                        status[self.id - Handle::MinId] = 2
                end
                
                method refresh
                        flag = true
                        refr = self
                        
                        ForGroup(refr, function add_ex)
                        
                        if flag
                                GroupClear(self)
                        end
                endfunction
                
                method each(callback: ->(Unit))
                        each_callback = callback
                        ForGroup(self, function each_forgroup)
                end
end
 
function wierd_stuff
        evil_units: Group = Group.new
        
        evil_units.each ->(evil_unit: Unit)
                # Get rid of 'em evil units
                KillUnit(evil_unit)
        end
        
        evil_units.free
end
 
class Effect
        function allocate(path: String, x: Real, y: Real): Effect
                return AddSpecialEffect(path, x, y)
        end
end
 
class Timer
        private
                static callbacks: ->[]
                
                function one_shot_wrapper
                        timer: Timer = GetExpiredTimer()
                        id: Integer = timer.id - Handle::MinId
                        callbacks[id]()
                        callbacks[id] = nil
                        PauseTimer(timer)
                        DestroyTimer(timer)
                end
                
        public
                function one_shot(time: Real, callback: ->)
                        timer: Timer = CreateTimer
                        callbacks[timer.id - Handle::MinId] = callback
                        TimerStart(Timer, time, false, function one_shot_wrapper)
                end
end
 
function timed_sfx(path: String, time: Real, x: Real, y: Real)
        sfx: Effect = Effect.new(path, x, y)
        
        Timer.one_shot(time) ->
                sfx.free
        end
end


But I guess the overhead is too much to get people to use it. It could allow some nice generators if it was inlined however.
__________________
Zoxc is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 10-13-2009, 02:45 PM   #2642
Anachron
User
 
Anachron's Avatar
 
Join Date: Mar 2009
Posts: 1,079

Anachron will become famous soon enough (51)Anachron will become famous soon enough (51)

Default

Increasing numeric variables with $var++; syntax?
I guess you won't at ZINC, because it is, as the name suggests, not c.
__________________
CustomInventory [Discussion - Download] - Got Directors Cut!
CustomMissle [Discussion - [Download (not yet)] - In development!
Other systems [Spawn System] [Move System] [CustomBar] [SpellBar]
Anachron is offline   Reply With Quote
Old 10-13-2009, 09:28 PM   #2643
Dark_Dragon
User
 
Dark_Dragon's Avatar
 
Join Date: Apr 2008
Posts: 189

Dark_Dragon has little to show at this moment (9)

Default

Quote:
Originally Posted by Vexorian
Problem is that this solution only works with ForGroup, what if you use the anonymous function for a trigger or a timer?

What if you use it to just assign a code variable?


Collapse Zinc:
type meh extends function(real) -> real;
...
      meh fn;
      code c;
      ...
      c = function(){  BJDebugMsg(I2S(x) ); };
      TimerStart(t, 5.0, false, c);
      TriggerAddAction(tr , c);

      TimerStart(t, 65.0, false,  function(){
             BJDebugMsg("65 seconds later");
      });
      TriggerAddCondition(tr ,   Condition(   function()->boolean  { return GetSpellId()==SPELL_ID; }    )  );


      fn = function(real x) -> real { 
            return Sin(x);
      };


i see! i never thought that they will be so powerfull :)

then implement it as u think is the best and ill be happy!

Greets!
~DD
__________________
Undefined shadow...
Dark_Dragon is offline   Reply With Quote
Old 10-14-2009, 03:13 AM   #2644
weaaddar
User


Respected User
 
Join Date: Apr 2002
Posts: 2,372

Submissions (3)

weaaddar has a spectacular aura about (131)

Default

Actually Vex,
I think in your example that you can do, you should do it in C# fashion and create basically a static variable x and assign it before usage.
dream code below::
Collapse Zinc:
int x = 0x10034;
ForGroup(g, function() { if x < GetHandleId(GetEnumUnit()) BJDebugMsg("Less than x"))};

could translate to...
Collapse JASS:
globals
integer AnonyFunc_0001_x
endglobals
function AnonyFunc_0001 takes nothing returns nothing
if(AnonyFunc_0001_x < GetHandleId(GetEnumUnit()) then
 call BJDebugMsg("Less than x"));
endif
enfunction

// in that caller
local integer x = 5;
set AnonyFunc_0001_x = x;
call ForGroup(g, function AnonyFunc_0001)
Or whatever as I haven't written pure Jass in a long time. I actually don't think its that hard and anonymous functions can then become passable entities that encapsulate their definitions.

Last edited by weaaddar : 10-14-2009 at 03:16 AM.
weaaddar is offline   Reply With Quote
Old 10-14-2009, 05:01 AM   #2645
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

that only happens when the function is going to be called right away, that's only true for ForGroup mostly. For timers and triggers, it would involve attaching and a lot of incredibly annoying things. Would have to decide between allowing it for ForGroup and dissallowing it for the rest, or doing it for the whole deal and then turn the task incredibly complicated (yet still impossible when you want it for function interfaces or assigning code variables (or using local arrays)

So, the question is, I either implement anonymous funcs as a way to implement functions in line without further usage of locals or things like that (I guess you would still be able to use private globals and static members) Or I just don't add anonymous functions.

ForGroup with static locals could turn into another construct , reminds me of this: http://www.wc3c.net/showthread.php?t=100417&page=3
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 10-14-2009, 05:07 AM   #2646
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

The closest thing to a correctly working multi-purpose anonymous function would be... an anonymous trigger.

Collapse Zinc:
        integer x= 3,y=5,z=8;
        trigger trig = trigger {
                   BJDebugMsg(I2S(x)+I2S(y)+I2S(z));
        };
        TriggerExecute(trig);


Collapse JASS:

function trig000 takes nothing returns nothing
 local integer t__  = GetHandleId( GetTriggeringTrigger() )
        call BJDebugMsg(   I2S(LoadHashTableInt(ht, t__, 0 ) )  +  I2S(LoadHashTableInt(ht, t__, 1 ))+I2S( LoadHashTableInt(ht, t__, 2 ) ));
endfunction

...
local integer x=3
local integer y=5
local integer z=8
local trigger trig = CreateTrigger()
    call TriggerAddAction(trig, function trig000)
    call SaveHashTableInt(ht, GetHandleId(trig), 0, x)
    call SaveHashTableInt(ht, GetHandleId(trig), 0, y)
    call SaveHashTableInt(ht, GetHandleId(trig), 0, z)
... But, DestroyTrigger is not the most reliable thing ever...
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 10-14-2009, 11:49 AM   #2647
weaaddar
User


Respected User
 
Join Date: Apr 2002
Posts: 2,372

Submissions (3)

weaaddar has a spectacular aura about (131)

Default

Which is fine really. Anyway there is no guarantee that the value set by the anony func should be ported forward after all, you've just now compiled a call-by-value entity. I'll verify the c# behavior later. And please the calling method for integer is like SaveInteger...


DestroyTrigger is fine, provided you destroy the triggeraction as well.

edit c# does forward port the value.
[zinc]
int x = 5;
Func<int> f =(() => x = x - 1);
Console.WriteLine(f());
Console.WriteLine(x);
Console.Read();
[/jass]

prints 4 newline 4.
I suppose the Jass could be handled as such...
Collapse Zinc:
global
integer Anony_Func_x;
integer Anony_Func_RetVal;
trigger Anony_Func_Trigger;
triggeraction Anony_Func_TriggerAction;
endglobals
function Anony_Func_X takes nothing returns nothing
      set Anony_Func_x = Anony_Func_x-1
      set Anony_Func_RetVal = Anony_Func_x
endfunction

//in the caller...
     local integer x = 5
     set Anony_Func_X = x
     Anony_Func_Trigger = CreateTrigger()
     Anony_Func_TriggerAction = TriggerAddAction(trig, function Anony_Func_x)
     call ExecuteTrigger(Anony_Func_Trigger)
     set x = Anony_Func_x
     call DestroyTriggerAction(Anony_Func_TriggerAction)
     call DestroyTrigger(Anony_Func_Trigger)
     call BJDeubgMsg(I2S(Anony_Func_RetVal))
     call BJDebugMsg(I2S(Anony_Func_x))
Although, you may not have to destroy these things right away. The user may want to keep his anonymous function/trigger and use it later. I'd be perfectly content if you made them a type, and that I can always just call Anony_Func.Dispose if I wanted to get rid of it.

I do see a need for both Anonymous functions (for Forgroup/ForForce/Boolexprs and all other code takers that tend to be quiet trivial), and anonymous triggers. The ideal would be both to be implemented, but I can see how its tricky.

Last edited by weaaddar : 10-14-2009 at 12:10 PM.
weaaddar is offline   Reply With Quote
Old 10-14-2009, 12:42 PM   #2648
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

I think I could just make it so if you use it a local inside an anonymous function it only works if you call it instantly... What I really like about the anonymous functions right now is to have a better code structure.

The user would have to destroy the trigger, some how we'll also need a hook to recycle the stuff. So a type is kind of necessary.
I really, really hate dynamic triggers ... Because I learned to distrust DestroyTrigger, the leak is one thing, but the fact that it can screw up the handle stack when you do not use it correctly (and lack of documentation means we'll never know we used it correctly...) Is very lame.

Anonymous triggers' flexibility also bounds us to triggers and hashtables, where there are really much faster ways to do that stuff.

So, how about I make anonymous functions, let use locals only when it is run right away, and be done with it?
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 10-14-2009, 02:18 PM   #2649
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

z.5
Vexorian is offline   Reply With Quote
Old 10-14-2009, 03:23 PM   #2650
Dark_Dragon
User
 
Dark_Dragon's Avatar
 
Join Date: Apr 2008
Posts: 189

Dark_Dragon has little to show at this moment (9)

Default

Quote:
Originally Posted by Vexorian
I think I could just make it so if you use it a local inside an anonymous function it only works if you call it instantly... What I really like about the anonymous functions right now is to have a better code structure.

The user would have to destroy the trigger, some how we'll also need a hook to recycle the stuff. So a type is kind of necessary.
I really, really hate dynamic triggers ... Because I learned to distrust DestroyTrigger, the leak is one thing, but the fact that it can screw up the handle stack when you do not use it correctly (and lack of documentation means we'll never know we used it correctly...) Is very lame.

Anonymous triggers' flexibility also bound us to triggers and hashtables, where there are really much faster ways to do that stuff.

So, how about I make anonymous functions, let use locals only when it is run right away, and be done with it?

yeah i as well like that new code structure with anonymous functions!

i just want em even if u dont allow locals in them!

Quote:
So, how about I make anonymous functions, let use locals only when it is run right away, and be done with it?

i agree with this!

~DD
__________________
Undefined shadow...

Last edited by Dark_Dragon : 10-14-2009 at 03:24 PM.
Dark_Dragon is offline   Reply With Quote
Old 10-14-2009, 03:46 PM   #2651
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (130)

Default

thistype doesn't seem to be supported in static ifs :

Collapse JASS:
struct S
    static constant boolean B = true
    
    method m1 takes nothing returns nothing
    
        static if S.B then
            // true
            call BJDebugMsg("true")
        else
            // false
            call BJDebugMsg("false")
        endif
        
    endmethod
    
endstruct

Collapse JASS:
    function s__S_m1 takes integer this returns nothing
    
            // true
            call BJDebugMsg("true")
        
    
            // true
    endfunction

Collapse JASS:
struct S
    static constant boolean B = true
    
    method m1 takes nothing returns nothing
    
        static if thistype.B then
            // true
            call BJDebugMsg("true")
        else
            // false
            call BJDebugMsg("false")
        endif
        
    endmethod
    
endstruct

Collapse JASS:
    function s__S_m1 takes integer this returns nothing
    
            // false
            call BJDebugMsg("false")
        
    
            // false
    endfunction

Also, as you can see the 2 comments are not added but the right comment is still doubled after the end of the static if.

Last edited by Troll-Brain : 10-14-2009 at 03:49 PM.
Troll-Brain is offline   Reply With Quote
Old 10-14-2009, 04:07 PM   #2652
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Quote:
Originally Posted by Vexorian
I think I could just make it so if you use it a local inside an anonymous function it only works if you call it instantly...
Yeah, this way makes the most sense.
grim001 is offline   Reply With Quote
Old 10-14-2009, 04:28 PM   #2653
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

Troll-brain: Yes, that was expected. thistype support will get added later.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 10-14-2009, 05:17 PM   #2654
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (130)

Default

Quote:
Originally Posted by Vexorian
Troll-brain: Yes, that was expected. thistype support will get added later.
Ok, but what about the double comment ?
Troll-Brain is offline   Reply With Quote
Old 10-14-2009, 05:40 PM   #2655
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

I can say it is not caused by the static if phase, but something that happens later, will take a look when there's more time.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 06:46 AM.


Donate

Affiliates
The Hubb http://bylur.com - Warcraft, StarCraft, Diablo and DotA Blog & Forums The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2014, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services