The parameter "case" determines what, in a script?
And, is it always used with a "switch?"
In layman's terms - case, What is it's purpose
Débuté par
Sonmeister
, avril 22 2010 10:38
#1
Posté 22 avril 2010 - 10:38
#2
Posté 23 avril 2010 - 08:08
In general, a switch is an effecient way to branch code into many paths based on the value of one variable.
The common useage in DA is to branch an event script based on which event was passed, or to branch a plot script based on which flag was passed.
The alternative is to just use a lot of if/else if statement. The switch is generaly easier to read however, and in most programing languages is a lot faster to run if you have a large number of cases becuase it can jump to the target case rather than checking the if statement one at a time.
The common useage in DA is to branch an event script based on which event was passed, or to branch a plot script based on which flag was passed.
The alternative is to just use a lot of if/else if statement. The switch is generaly easier to read however, and in most programing languages is a lot faster to run if you have a large number of cases becuase it can jump to the target case rather than checking the if statement one at a time.
#3
Posté 24 avril 2010 - 03:33
Sunjammer wrote...
But does it run faster in dascript?DavidSims wrote...
... in most programing languages is a lot faster to run if you have a large number of cases becuase it can jump to the target case rather than checking the if statement one at a time.
I honestly don't know for sure, but I doubt it. Even in C you have to have a pretty big switch before it makes an appreciable difference. I think compilers generaly translate small switch statements into if/else if blocks anyway. It wouldn't suprise me if dascript did that translation for all switch statements.
If all your script is doing is integer comparisons, you'd have to be doing a pretty extreem number to notice a performance difference compared to the base overhead of loading and running any script. I don't think the the switch is going to matter. When scripts slow the game down, it tends to be an excesive number of different scripts running, an excesive number of string opperations or the script causing the game engine to do something proccessor intensive or accessing data which isn't in memory.





Retour en haut






