switch/case
Moderator: Event DM
- TheBluDragon
- Prince of Bloated Discourse
- Posts: 279
- Joined: Tue Jan 21, 2003 3:26 pm
- Location: Bunbury, Western Australia (AWST: UTC+8 / GMT+8)
switch/case
I am trying to use a switch/case statement.
ok, I know it exists, can someone point me to a working example so I can use it.
I s'pose the time of night I am trying to get this working dosent help.
As another idea, can anyone tell me how I can have an if statement with multiple conditions? ie, the PC has item #1, OR item #2 OR item #3 (or any combination), then it executes the code. I am planning to use the switch/case to do this, but there must be a simpler way using 'if'.
ok, I know it exists, can someone point me to a working example so I can use it.
I s'pose the time of night I am trying to get this working dosent help.
As another idea, can anyone tell me how I can have an if statement with multiple conditions? ie, the PC has item #1, OR item #2 OR item #3 (or any combination), then it executes the code. I am planning to use the switch/case to do this, but there must be a simpler way using 'if'.
"Evil is a point of view. God kills indiscriminately and so shall we. For no creatures under God are as we are, none so like him as ourselves" - Lestat
- Neve
- Prince of Bloated Discourse
- Posts: 192
- Joined: Mon Apr 14, 2003 4:09 pm
- Location: The Netherlands
- Contact:
Code: Select all
switch(d3()){
case 1 : <blablablabla>;
break;
case 2 : <blablablabla>;
break;
case 3 : <blablablabla>;
break;
}
About testing for either this or that item, you should use the pipes : ||
Code: Select all
if(GetIsDay() || GetIsDawn()) DoSomething();
else DoSomethingElse();
- As you gaze unknowingly into the seemingly infinite depths of the optics of this altogether passionate embodiment of insatiability, you experience a gradual realisation that the heavily-embellished vocabulary scattered lavishly throughout the sentence you are currently reading is indisputably nothing greater than a generous ration of masculine bovine faeces.
- JollyOrc
- Elder Sage
- Posts: 3984
- Joined: Fri Jan 17, 2003 11:41 am
- Timezone: Europe, CE(S)T
- Location: Germany
- Contact:
am I remembering it right when I say that switch - case only checks integers ? So no
?
Code: Select all
switch (name) {
case "John" : <blablablabla>;
break;
case "joe": <blablablabla>;
break;
}
- Neve
- Prince of Bloated Discourse
- Posts: 192
- Joined: Mon Apr 14, 2003 4:09 pm
- Location: The Netherlands
- Contact:
2g.nss(5): ERROR: NON INTEGER EXPRESSION WHERE INTEGER REQUIREDJollyOrc wrote:am I remembering it right when I say that switch - case only checks integers ? So no
?Code: Select all
switch (name) { case "John" : <blablablabla>; break; case "joe": <blablablabla>; break; }

- As you gaze unknowingly into the seemingly infinite depths of the optics of this altogether passionate embodiment of insatiability, you experience a gradual realisation that the heavily-embellished vocabulary scattered lavishly throughout the sentence you are currently reading is indisputably nothing greater than a generous ration of masculine bovine faeces.
- Lafferty
- Scholar
- Posts: 1129
- Joined: Tue Feb 11, 2003 5:08 pm
- Location: look at my hands... they are HUGE. And they cant touch themselves...
- Contact:
Just convert your values to something integer in the case of a string make it:
"John" -> (J = 074;o = 111; h = 104; n = 110) -> 074111104110

LOL
*slaps head* what a chaotic concept and make the keyword a bit longer and thats it
ok this is not so good... maybe store your Strings in an array/hash and get the position of an entry and compare to that?
ok i should go home and eat someting instead of drinking coffee all day and posting crap
"John" -> (J = 074;o = 111; h = 104; n = 110) -> 074111104110

LOL

ok this is not so good... maybe store your Strings in an array/hash and get the position of an entry and compare to that?
ok i should go home and eat someting instead of drinking coffee all day and posting crap

- Neve
- Prince of Bloated Discourse
- Posts: 192
- Joined: Mon Apr 14, 2003 4:09 pm
- Location: The Netherlands
- Contact:
Actually,
You could also change your Random function like this :
Instead of Random(37), which generates values from 0 - 37
Random(36) + 1, which generates values from 1 - 37
As for arrays, you could try to make a linked list instead, with a '%%' or something to divide the strings/integers you'd like to save
You could also change your Random function like this :
Instead of Random(37), which generates values from 0 - 37
Random(36) + 1, which generates values from 1 - 37

As for arrays, you could try to make a linked list instead, with a '%%' or something to divide the strings/integers you'd like to save

- As you gaze unknowingly into the seemingly infinite depths of the optics of this altogether passionate embodiment of insatiability, you experience a gradual realisation that the heavily-embellished vocabulary scattered lavishly throughout the sentence you are currently reading is indisputably nothing greater than a generous ration of masculine bovine faeces.
- TheBluDragon
- Prince of Bloated Discourse
- Posts: 279
- Joined: Tue Jan 21, 2003 3:26 pm
- Location: Bunbury, Western Australia (AWST: UTC+8 / GMT+8)
Ok, cool. Thanks for that.Neve wrote:If you use the "Random" function, you should start with "case 0"Code: Select all
switch(d3()){ case 1 : <blablablabla>; break; case 2 : <blablablabla>; break; case 3 : <blablablabla>; break; }
About testing for either this or that item, you should use the pipes : ||
Code: Select all
if(GetIsDay() || GetIsDawn()) DoSomething(); else DoSomethingElse();
Also, to extend this a little, would the double ampersand(sp?) && instead of the pipes || make it AND instead of OR ?? Compiles fine, but havent had a chance to test it out yet. If not what should it be?
Code: Select all
if(GetIsDay() && GetIsCloudy()) DoSomething();
else DoSomethingElse();
"Evil is a point of view. God kills indiscriminately and so shall we. For no creatures under God are as we are, none so like him as ourselves" - Lestat
Correct, && is the symbol for logical AND. ! is the symbol for logical NOT, and || is the symbol for logical OR. The correct way to form up a switch/case type structure for non-integer options (like strings) is like this:
You'll notice it's VERY similar to the switch organization and it works very well. Just make sure you're testing the same string against multiple values, or the flow of the ifs can end up missing an if you were counting on hitting 
Myk D'Vor
Code: Select all
if(string=="blah") {
SpeakString("it was blah");
} else if (string=="foo") {
SpeakString("it was foo");
} else if (string=="bar") {
SpeakString("it was bar");
} else if (string=="foobar") {
SpeakString("it was foobar");
}

Myk D'Vor
- TheBluDragon
- Prince of Bloated Discourse
- Posts: 279
- Joined: Tue Jan 21, 2003 3:26 pm
- Location: Bunbury, Western Australia (AWST: UTC+8 / GMT+8)
I still cant seem to get this to work correctly, and I need help badly.
I am trying to get it to return true if the PC is carrying any 1 of 5 different items.
What it currently does is tests that PC has ALL the items, which makes no sense to me, surely "else" means "if this then ... else this" ie. if not the first one, then the secone one ...
The effect it will have, is that if they are carrying one of these items, it will start 1 conversation tree, if they have none of them, it will be something different.
Works fine if I do it with only 1 item, but I need the 5 different items for other parts of the script. I have tried it without the "else" and without the "{}" so I am pretty much stuck.
I am trying to get it to return true if the PC is carrying any 1 of 5 different items.
Code: Select all
if(!HasItem(GetPCSpeaker(), "Item1")) {
return TRUE;
} else if(!HasItem(GetPCSpeaker(), "Item2")){
return TRUE;
} else if(!HasItem(GetPCSpeaker(), "Item3")){
return TRUE;
} else if(!HasItem(GetPCSpeaker(), "Item4")){
return TRUE;
} else if(!HasItem(GetPCSpeaker(), "Item5")){
return TRUE;
}
return FALSE;
The effect it will have, is that if they are carrying one of these items, it will start 1 conversation tree, if they have none of them, it will be something different.
Works fine if I do it with only 1 item, but I need the 5 different items for other parts of the script. I have tried it without the "else" and without the "{}" so I am pretty much stuck.
"Evil is a point of view. God kills indiscriminately and so shall we. For no creatures under God are as we are, none so like him as ourselves" - Lestat
- JollyOrc
- Elder Sage
- Posts: 3984
- Joined: Fri Jan 17, 2003 11:41 am
- Timezone: Europe, CE(S)T
- Location: Germany
- Contact:
Code: Select all
if (!HasItem(GetPCSpeaker(), "Item1"))
return TRUE;
if (!HasItem(GetPCSpeaker(), "Item2"))
return TRUE;
if (!HasItem(GetPCSpeaker(), "Item3"))
return TRUE;
if (!HasItem(GetPCSpeaker(), "Item4"))
return TRUE;
if (!HasItem(GetPCSpeaker(), "Item5"))
return TRUE;
return FALSE;
If the items are named as that a loop might be more easily readable, and can handle way more than 5 items.
- TheBluDragon
- Prince of Bloated Discourse
- Posts: 279
- Joined: Tue Jan 21, 2003 3:26 pm
- Location: Bunbury, Western Australia (AWST: UTC+8 / GMT+8)
These are not the actual Item names I am using, but suffice to say, the actual names are unique, and readable.
The effect this has is that the PC must have all the items for it to read true, which is not what I want. I want it to read true if the PC has any of the items.
The effect this has is that the PC must have all the items for it to read true, which is not what I want. I want it to read true if the PC has any of the items.
"Evil is a point of view. God kills indiscriminately and so shall we. For no creatures under God are as we are, none so like him as ourselves" - Lestat
It'd be ugly as hell, but couldn't you just do:
Can NWScript handle a multiple OR statement like that?
Bye Now,
Jerry Cornelius - include BEER.H
Code: Select all
if ((!HasItem(GetPCSpeaker(), "Item1"))) || ((!HasItem(GetPCSpeaker(), "Item2"))) || ((!HasItem(GetPCSpeaker(), "Item3"))) || ((!HasItem(GetPCSpeaker(), "Item4"))) || ((!HasItem(GetPCSpeaker(), "Item5")))
return TRUE;
Bye Now,
Jerry Cornelius - include BEER.H
Everything I need to know in life, I learned from being an alcoholic.
- TheBluDragon
- Prince of Bloated Discourse
- Posts: 279
- Joined: Tue Jan 21, 2003 3:26 pm
- Location: Bunbury, Western Australia (AWST: UTC+8 / GMT+8)