转自 ExtendSim 英文论坛
: Z, G5 E# n+ w; f4 F# U1 \) w& _; l. P& s1 c
Question:
$ P$ m; Y/ ]: d. x$ @4 u
/ H0 _% j a/ M& c) a, s2 nI know that you can use the underlying integer for a string attribute within an equation block. However, I would like to be able to use the string value.6 U- Q( ?9 E: C7 V/ d
For example if I have a string attribute called "State" with possible values "PA" and "NC" I know the following equation would work properly:$ {) Q2 }- g r( t# V- T
if (State == 1) then% u% e& ]' \4 D+ U' r: J
outCon0 = 1;
& b+ T% T$ {4 k- e; s# T" relseif (State == 2) then
: L) q2 @$ @# U9 Z# T outCon0 = 2;6 A$ h- `; |" q3 q( n
else3 [) h" M5 ^- S! s* B
outCon0 = 0;7 b1 y" l$ e m
However, I want the following to work but don't know how in Extend
1 _" j s( h3 {# M, q4 Dif (State == "PA") then
0 k1 ]' q0 d$ ` y9 V7 ]3 o outCon0 = 1;
, W. a; m8 ^7 ?4 |. p$ Eelseif (State == "NC") then/ c X* h; S- M9 |$ B5 V O) \& r
outCon0 = 2;
8 q, V% w$ _: D Y& q! ielse
, T. ~: T( S8 C- ?7 {, R outCon0 = 0;
* x/ {2 e7 h) z; c
' b7 t* w( g1 Z, q
- T7 W9 f- K" D. l9 ^" l+ B; kAnswer: 6 E$ s3 ]+ y0 x7 O( J4 G+ G
! p! F! \% g$ g7 {' \' LThat's a good question. In ExtendSim string attributes are stored as integers which are used as indexes into arrays of strings. This is efficient for both performance and memory. The following equation will get the string from the attribute:/ u, n% w1 W8 q; `
6 r! f$ z: K7 X, B
if(SLStringGet("State", State) == "NC") Path = 0;( T( T% I0 ?: a" X* W! e
else if(SLStringGet("State", State) == "PA") Path = 1;$ ]! D" A b0 W }: Q2 i. w& J
else abort;
. X2 v+ f8 |2 o0 d2 x1 u$ f6 x( }9 g% v
I put the abort in at the end so if there was a string that was not in the equation, it would be caught by the model. |