|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Oct 23, 2006 8:31 pm
New alternate syntax for #SWITCH |
While working on the parser today, I discovered that it was easy to handle an alternate syntax for #SWITCH that will make some scripts a lot easier.
The normal syntax for #SWITCH is this:
Code: |
#SWITCH (expr1) {command1} (expr2) {command2} ... {optional else command} |
In the above case, each expression (expr1, expr2, etc) is evaluated until one is found to be true. Then the command following the expression is executed.
Here is the new alternative syntax in v1.12:
Code: |
#SWITCH (MasterExpr) (expr1) {command1} (expr2) {command2} ... {optional else command} |
Notice that there is a new MasterExpr expression at the beginning. This syntax is equivalent to this:
Code: |
#SWITCH (MasterExpr = expr1) {command1} (MasterExpr = expr2) {command2} ... {optional else command} |
For example, let's say you want to test the value of the @a variable and do different things depending upon it's values. In the normal #SWITCH syntax you would do this:
Code: |
#SWITCH (@a=1) {one} (@a=2) {two} (@a=3) {three} ... |
In the new alternative syntax, you can do this:
Code: |
#SWITCH @a 1 {one} 2 {two} 3 {three} |
or, using the multiline syntax:
Code: |
#SWITCH @a
1 {one}
2 {two}
3 {three}
{optional else} |
which works more like the normal switch statement in C.
Note that in this simple case, the () around the expressions wasn't needed because the expressions were simple.
I normally don't want to make complicated changes to the parser, but since this turned out to be really easy to add without messing up other stuff, I went ahead with it in 1.12. Hope people like it. |
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Mon Oct 23, 2006 9:05 pm |
Sounds very cool, Zugg. I'm sure it will be very useful.
|
|
|
|
slicertool Magician
Joined: 09 Oct 2003 Posts: 459 Location: USA
|
Posted: Sat Nov 11, 2006 10:47 am |
Sorry, I missed this post initially and was trying to find a copy of my code sample that I posted. This makes my code a lot easier.
Code: |
#alias k {
#if (%alarm( ShapeAlarm3) = -1) {kill %0} {
#SWITCH (@LastRace)
("rodian") {surprise %0}
("sullustan") {confuse %0}
("defel") {claw %0}
("noghri") {stab %0}
("bothan") {avoid}
("mon calamari") {gas %0}
("sluissi") {tailwhip %0}
("ewok") {tumble %0}
("falleen") {baffle %0}
("gamorrean") {bash %0}
("gungan") {lunge %0}
("gand") {strike %0}
("human") {influcence %0}
("jawa") {surprise %0}
("togorian") {grapple %0}
("trandoshan") {tear %0}
("twi'lek") {trip %0}
("verpine") {rake %0}
("wookiee") {rage}
("zabrak") {anticipate}
("ithorian") {#if (%0 <> "") {#var SkillTarget %0};strengthen @SkillTarget}
("bimm") {bsing}
}} |
|
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|