Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
6 registered members (AndrewAMD, Ayumi, degenerate_762, 7th_zorro, VoroneTZ, HoopyDerFrood), 1,268 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
switch () with C-Script #235306
11/06/08 22:13
11/06/08 22:13
Joined: Jul 2002
Posts: 2,002
Europe
ShoreVietam Offline OP
Expert
ShoreVietam  Offline OP
Expert

Joined: Jul 2002
Posts: 2,002
Europe
Good evening beloved developers,

for those still using C-Script (like me) I found a way faking switch () by using the while () instuction.

Maybe it looks a bit strange in the beginning, but it aviods those if () structures that look like chinese temples.


Code:
while (1) {
	// Case 1
	if (expression) {
		instructions
		break;
	}
	// Case 2
	if (expression) {
		instructions
		break;
	}
	// And so on...

	// Default part
	instructions
	break;
}


Last edited by ShoreVietam; 11/06/08 22:14.

My project Schlacht um Kyoto - Das Samurai Browsergame! (sorry, german only)
Re: switch () with C-Script [Re: ShoreVietam] #235339
11/07/08 03:35
11/07/08 03:35
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Why do you put that in a loop? The loop does not make sense at all as it is never executed.


Always learn from history, to be sure you make the same mistakes again...
Re: switch () with C-Script [Re: ShoreVietam] #235351
11/07/08 08:32
11/07/08 08:32
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline
Serious User
Lion_Ts  Offline
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
sorry, it seems that snippet is useless... write if operators without 'deep' indent to visually emulate switch operator, like this:
Code:
 
if (expr)
{
  // case 1
}
else if (expr)
{
  // case 2
}
else
{
  // default
)


Re: switch () with C-Script [Re: Lion_Ts] #235435
11/07/08 16:35
11/07/08 16:35
Joined: Jul 2002
Posts: 2,002
Europe
ShoreVietam Offline OP
Expert
ShoreVietam  Offline OP
Expert

Joined: Jul 2002
Posts: 2,002
Europe
@Lion_Ts

A6.31.4 C-Script (and earlyer) does understand if-structures without {} (having only one following command, which can be another if, to create what you posted).

Your if structure in C-Script looks like this:

Code:
if (expression) {

} else { if (expression) {

} else { if (expression) {

} else {

} } }


And is aweful to count the amount of closing-brackets.


So why the while?
To be able to jump to the end of the fake-switch by using break;.




Last edited by ShoreVietam; 11/07/08 16:36.

My project Schlacht um Kyoto - Das Samurai Browsergame! (sorry, german only)
Re: switch () with C-Script [Re: ShoreVietam] #235481
11/07/08 21:35
11/07/08 21:35
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
if else if else does actually not represent the logic behind a switch instruction. In a switch instruction you have multiple possibilities and a default case. If you want to rebuild switch you can do it the closest way like this:
Code:
if (condition1){
  doSomething()1;
}
if (condition2){
  doSomething()2;
}
doSomethingDefault();

So there is no need (and even no sense) in using else branches and counting brackets. The breaks of the switch instruction can be easily simulated by goto. I wouldn't recomment using loops and breaks for this case as a loop suggests other readers of your code that you want to do somehting totally different.


Always learn from history, to be sure you make the same mistakes again...
Re: switch () with C-Script [Re: Uhrwerk] #235486
11/07/08 22:27
11/07/08 22:27
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
Goto is crap. Never use it!

Re: switch () with C-Script [Re: FBL] #235489
11/07/08 22:46
11/07/08 22:46
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
It's ok as long as you get the control over it. I personally wouldn't use gotos too. But I'd prefer a goto statement to a semi-switch-like construction that requires a loop that is never looped. ;-)


Always learn from history, to be sure you make the same mistakes again...
Re: switch () with C-Script [Re: Uhrwerk] #235502
11/08/08 00:11
11/08/08 00:11
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
'else if' is crap. Never include it in 'your' scripting language. Later the omission might be used to bolster an insanity defense.

Thank you, ShoreVietnam. That fine example can be used as a testament to the absurd limitations of a deviant scripting language spawned in the abyss, the ingenuity of those poor souls that used it (and still do), the cruelty of the depraved entity which spawned it, and the bold-n-sure argumentative infection left in its wake.
wink tired sick crazy

Re: switch () with C-Script [Re: testDummy] #235505
11/08/08 00:26
11/08/08 00:26
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
Why not just use Lite-C? smile
It will crank up our heads less.... well... uh... hopefully at least laugh

Re: switch () with C-Script [Re: FBL] #235560
11/08/08 14:25
11/08/08 14:25
Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Puppeteer Offline
Expert
Puppeteer  Offline
Expert

Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Originally Posted By: Firoball
Why not just use Lite-C? smile
It will crank up our heads less.... well... uh... hopefully at least laugh

Because c-script rulz!!!!!!!111111111111111oneoneoneeleven


Formally known as Omega
Avatar randomness by Quadraxas & Blade
http://omegapuppeteer.mybrute.com
Page 1 of 2 1 2

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1