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.

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, 07:26 PM
GetTriggerUnit-'s Avatar
GetTriggerUnit- GetTriggerUnit- is offline
You can change this now in User CP.
 
Join Date: May 2009
Posts: 1,002
GetTriggerUnit- is starting to get some respect (+100)GetTriggerUnit- is starting to get some respect (+100)
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, 07:32 PM
jomik jomik is offline
Junior Member (Am I really helping anyone?)
 
Join Date: Oct 2009
Posts: 274
jomik has zero reputation
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, 07:36 PM
Tyrulan's Avatar
Tyrulan Tyrulan is offline
Veteran Member (Done that)
 
Join Date: Aug 2006
Posts: 453
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, 07:38 PM
GetTriggerUnit-'s Avatar
GetTriggerUnit- GetTriggerUnit- is offline
You can change this now in User CP.
 
Join Date: May 2009
Posts: 1,002
GetTriggerUnit- is starting to get some respect (+100)GetTriggerUnit- is starting to get some respect (+100)
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, 08:06 PM
kingkingyyk3's Avatar
kingkingyyk3 kingkingyyk3 is offline
Using Windows 7 | Click Me!®
 
Join Date: Feb 2009
Location: Malaysia
Posts: 1,661
kingkingyyk3 seems to have the helping tendency (+150)kingkingyyk3 seems to have the helping tendency (+150)
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, 08:43 PM
Lyerae's Avatar
Lyerae Lyerae is offline
Junior Regular (Got the T-shirt)
 
Join Date: May 2009
Location: Meridian, MS.
Posts: 816
Lyerae is starting to make their name known (+75)
Switch could be useful.
Reply With Quote
  #7  
Old November 6th, 2009, 09:55 PM
GetTriggerUnit-'s Avatar
GetTriggerUnit- GetTriggerUnit- is offline
You can change this now in User CP.
 
Join Date: May 2009
Posts: 1,002
GetTriggerUnit- is starting to get some respect (+100)GetTriggerUnit- is starting to get some respect (+100)
Reply With Quote
  #8  
Old November 7th, 2009, 01:38 AM
ertaboy356b's Avatar
ertaboy356b ertaboy356b is offline
blog -- http://www.retroedd.co.cc
 
Join Date: Feb 2007
Location: www.jump08.co.nr
Posts: 1,242
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, 02:32 AM
Lyerae's Avatar
Lyerae Lyerae is offline
Junior Regular (Got the T-shirt)
 
Join Date: May 2009
Location: Meridian, MS.
Posts: 816
Lyerae is starting to make their name known (+75)
Yeah.
I'd remove the endswitch keyword though.
Reply With Quote
  #10  
Old November 7th, 2009, 06:22 AM
Jesus4Lyf Jesus4Lyf is online now
Good Idea™
 
Join Date: Jul 2007
Location: Australia
Posts: 2,663
Jesus4Lyf has much to be proud of (+800)Jesus4Lyf has much to be proud of (+800)Jesus4Lyf has much to be proud of (+800)Jesus4Lyf has much to be proud of (+800)Jesus4Lyf has much to be proud of (+800)Jesus4Lyf has much to be proud of (+800)Jesus4Lyf has much to be proud of (+800)
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, 04:44 PM
Nestharus's Avatar
Nestharus Nestharus is offline
Junior Regular (Got the T-shirt)
 
Join Date: Aug 2006
Location: Somewhere between here an
Posts: 733
Nestharus has started helping a few people (+50)
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, 04:58 PM
Tyrulan's Avatar
Tyrulan Tyrulan is offline
Veteran Member (Done that)
 
Join Date: Aug 2006
Posts: 453
Tyrulan seems to be trying to help (+25)
It's user friendly. To me, anyway.
Reply With Quote
  #13  
Old November 7th, 2009, 06:23 PM
Themis's Avatar
Themis Themis is offline
Member of clan BoM!
 
Join Date: Sep 2006
Location: Amsterdam
Posts: 570
Themis seems to have the helping tendency (+150)Themis 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 Themis; November 7th, 2009 at 06:29 PM.
Reply With Quote
  #14  
Old November 7th, 2009, 06:33 PM
T.s.e's Avatar
T.s.e T.s.e is offline
Serious nose is superior
 
Join Date: Jan 2008
Location: Norway.
Posts: 1,001
T.s.e is being taken more seriously (+250)T.s.e is being taken more seriously (+250)T.s.e is being taken more seriously (+250)
I really don't see what the point of this is.
Reply With Quote
  #15  
Old November 7th, 2009, 06:39 PM
Nestharus's Avatar
Nestharus Nestharus is offline
Junior Regular (Got the T-shirt)
 
Join Date: Aug 2006
Location: Somewhere between here an
Posts: 733
Nestharus has started helping a few people (+50)
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 08:42 PM.


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