The Helper Forums
The Helper offers free technical support for computer games,
computer hardware, and other computer software. Staffed
by volunteer tech support workers, The Helper is highly
regarded as a premium destination for those who are
experiencing technical problems with their computers.
Affiliate Sites
Warcraft 3 World Editor Tutorials - The Greatest Resource for the new Warcraft 3 Mapper
Silkroad Online Forums
Houston Microsoft Access, VBA and Visual Basic Programming
The source for NUON news, information, and games.
Griffonrawl Muay Thai and MMA
Warcraft 3 Modding Site.
Element Tower Defense by Karawasa.
Topaz Games.
Chernobyl Lost Riddles

Able Auto Glass specializes in Houston Auto Glass Replacement as well as windshield repair and replacement services.
Apex Steel Pipe - Buys and sells Used Steel Pipe.

Go Back   The Helper Forums > Warcraft Zone > World Editor Help > JASS Help

Reply
 
Thread Tools Display Modes
  #1  
Old November 6th, 2009, 06:26 PM
GetTriggerUnit-'s Avatar
GetTriggerUnit- GetTriggerUnit- is offline
.
 
Join Date: May 2009
Posts: 1,311
GetTriggerUnit- seems to have the helping tendency (+150)GetTriggerUnit- seems to have the helping tendency (+150)
Adding switch(){} statement to jasshelper (good/bad idea)?

I had the idea, while doing c++, to suggest adding the switch statement to jasshelper. (For those who don't know what the switch statement is: Switch statement)

Exemple
Jass:
function Test takes nothing returns nothing
    local integer value=15
    switch(value)
        case 5 {
            call DoSomething(5)
            break
        }
        case 10 {
            call DoSomething(10)
            break
        }
        case 15 {
            call DoSomething(15)
            break
        }
        default {
            call DoNothing()
            break
        }
    endswitch
endfunction

Good idea? Opinions please .
Reply With Quote
  #2  
Old November 6th, 2009, 06:32 PM
jomik jomik is offline
Veteran Member (Done that)
 
Join Date: Oct 2009
Posts: 466
jomik has received some positive rep  (+10)
Well, your example looks like it could be rewritten to:
Jass:
function Test takes nothing returns nothing
    local integer value=15
    if (value != 0)
        call DoSomething(value)
    endif
endfunction

But if it is what I think it is, then it's goodies
But it can already be made with if statements?
Reply With Quote
  #3  
Old November 6th, 2009, 06:36 PM
Tyrulan's Avatar
Tyrulan Tyrulan is offline
Junior Regular (Got the T-shirt)
 
Join Date: Aug 2006
Posts: 560
Tyrulan seems to be trying to help (+25)
If statements yes, but this is more organized. I like it. Plus shorter to write if you have many conditions you avoid long statements ... or or or and or or and and or....
Reply With Quote
  #4  
Old November 6th, 2009, 06:38 PM
GetTriggerUnit-'s Avatar
GetTriggerUnit- GetTriggerUnit- is offline
.
 
Join Date: May 2009
Posts: 1,311
GetTriggerUnit- seems to have the helping tendency (+150)GetTriggerUnit- seems to have the helping tendency (+150)
Basicly, it would be rewriten with if statements but the main idea is that it's shorter to write and looks neater, Imo..
Reply With Quote
  #5  
Old November 6th, 2009, 07:06 PM
kingkingyyk3's Avatar
kingkingyyk3 kingkingyyk3 is offline
Visitor (Welcome to the Jungle, Baby!)
 
Join Date: Feb 2009
Posts: 2,775
kingkingyyk3 is doing a good job (+300)kingkingyyk3 is doing a good job (+300)kingkingyyk3 is doing a good job (+300)kingkingyyk3 is doing a good job (+300)
Suggest to cJass, it uses c style. vJass is fine, if you want to use shortcut, use Zinc.
Reply With Quote
  #6  
Old November 6th, 2009, 07:43 PM
Lyerae Lyerae is offline
Hai.
 
Join Date: May 2009
Posts: 1,882
Lyerae seems to have the helping tendency (+150)Lyerae seems to have the helping tendency (+150)
Switch could be useful.
Reply With Quote
  #7  
Old November 6th, 2009, 08:55 PM
GetTriggerUnit-'s Avatar
GetTriggerUnit- GetTriggerUnit- is offline
.
 
Join Date: May 2009
Posts: 1,311
GetTriggerUnit- seems to have the helping tendency (+150)GetTriggerUnit- seems to have the helping tendency (+150)
Reply With Quote
  #8  
Old November 7th, 2009, 12:38 AM
ertaboy356b's Avatar
ertaboy356b ertaboy356b is offline
blog -- http://syncjournal.blogspot.com
 
Join Date: Feb 2007
Location: www.jump08.co.nr
Posts: 1,399
ertaboy356b seems to have the helping tendency (+150)ertaboy356b seems to have the helping tendency (+150)
switch is useful.. I mostly use it if I have a lot of if statements..
Reply With Quote
  #9  
Old November 7th, 2009, 01:32 AM
Lyerae Lyerae is offline
Hai.
 
Join Date: May 2009
Posts: 1,882
Lyerae seems to have the helping tendency (+150)Lyerae seems to have the helping tendency (+150)
Yeah.
I'd remove the endswitch keyword though.
Reply With Quote
  #10  
Old November 7th, 2009, 05:22 AM
Jesus4Lyf Jesus4Lyf is offline
Good Idea™
 
Join Date: Jul 2007
Location: Australia
Posts: 3,857
Jesus4Lyf has a reputation beyond repute (+1000)Jesus4Lyf has a reputation beyond repute (+1000)Jesus4Lyf has a reputation beyond repute (+1000)Jesus4Lyf has a reputation beyond repute (+1000)Jesus4Lyf has a reputation beyond repute (+1000)Jesus4Lyf has a reputation beyond repute (+1000)Jesus4Lyf has a reputation beyond repute (+1000)Jesus4Lyf has a reputation beyond repute (+1000)Jesus4Lyf has a reputation beyond repute (+1000)
It is all crap. It is more efficient (and perhaps even readable) if you have enough cases to do:
Jass:
function Test takes nothing returns nothing
    local integer value=15
    call MySwitchCases[value].evaluate()
endfunction
And fill "MySwitchCases" with function pointers on init.

Heck, you can make MySwitchCases a trigger array directly and add triggers with conditions and just do call TriggerEvaluate(MySwitchCases[value]).

(Switch is just an O(n) complexity way of doing this, so to speak.)
Reply With Quote
  #11  
Old November 7th, 2009, 03:44 PM
Nestharus's Avatar
Nestharus Nestharus is offline
o-o
 
Join Date: Aug 2006
Posts: 1,223
Nestharus is starting to get some respect (+100)Nestharus is starting to get some respect (+100)
In JASS, it really wouldn't matter whether you were using a switch statement or a set of ifs. In compiled programming, the switch statement immediately goes to the set case. In compiled programming, switch statements are faster than ifs -.-, but this isn't compiled programming is it? It's interpretive, so it really doesn't matter which way or the other .


Jesus4Lyf's a good idea for maintainability and for speed if you end up having a million else ifs.

I don't believe a switch statement would merit any benefit whatsoever to the JASS language ;D.
Reply With Quote
  #12  
Old November 7th, 2009, 03:58 PM
Tyrulan's Avatar
Tyrulan Tyrulan is offline
Junior Regular (Got the T-shirt)
 
Join Date: Aug 2006
Posts: 560
Tyrulan seems to be trying to help (+25)
It's user friendly. To me, anyway.
Reply With Quote
  #13  
Old November 7th, 2009, 05:23 PM
Xorifelse's Avatar
Xorifelse Xorifelse is offline
I'd love to elaborate about discussions...........
 
Join Date: Sep 2006
Location: Amsterdam
Posts: 650
Xorifelse seems to have the helping tendency (+150)Xorifelse seems to have the helping tendency (+150)
This would not be really possible in Jass, because if 1 case returns true it should execute every case below as well.
Meaning this can only be done with a lot of preset booleans for a case.

So your example should be converted to this:
Jass:
function Test takes nothing returns nothing
    local integer value=15
    local boolean a = false
    local boolean b = false
    local boolean break = false

    if( value == 5 ) then
        set a = true
        set break = true
        call DoSomething(value)
    elseif (value == 10) or ((break == false) and (a == true)) then
        set b = true
        set break = true
        call DoSomething(value)
    elseif (value == 15) or ((break == false) and (b == true)) then
        call DoSomething(value)
    elseif (true) and ( (break == false) and (a == false) and (b == false)) then // dunno if default switch case is executed when every case returns false, otherwise it's a simple "elseif true then")
        call DoNothing()
        // The last break here in your code does not make any sense.
    endif
endfunction

Perhaps this code is not fully accurate in the way switch really works but you should get the idea. This causes a lot of technical difficulties and a lot of more compute time as well.

If-then-else works good, if you don't like the syntax use zinc, otherwise don't complain.

Last edited by Xorifelse; November 7th, 2009 at 05:29 PM.
Reply With Quote
  #14  
Old November 7th, 2009, 05:33 PM
T.s.e's Avatar
T.s.e T.s.e is offline
Follow me down, to the valley below...
 
Join Date: Jan 2008
Location: Norway.
Posts: 1,108
T.s.e is doing a good job (+300)T.s.e is doing a good job (+300)T.s.e is doing a good job (+300)T.s.e is doing a good job (+300)
I really don't see what the point of this is.
Reply With Quote
  #15  
Old November 7th, 2009, 05:39 PM
Nestharus's Avatar
Nestharus Nestharus is offline
o-o
 
Join Date: Aug 2006
Posts: 1,223
Nestharus is starting to get some respect (+100)Nestharus is starting to get some respect (+100)
You and me both

Quote:
In JASS, it really wouldn't matter whether you were using a switch statement or a set of ifs. In compiled programming, the switch statement immediately goes to the set case. In compiled programming, switch statements are faster than ifs -.-, but this isn't compiled programming is it? It's interpretive, so it really doesn't matter which way or the other .


Jesus4Lyf's a good idea for maintainability and for speed if you end up having a million else ifs.

I don't believe a switch statement would merit any benefit whatsoever to the JASS language ;D.
Reply With Quote
Reply

Thread Tools
Display Modes

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

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

Forum Jump


All times are GMT -5. The time now is 11:19 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.