转自 ExtendSim 英文论坛
( ^" g' f/ F% s9 y& y; L A& v4 v7 t" y3 {
Question:
0 C4 H0 n' ~: N% M+ E5 F R0 H. B2 Y T4 X1 T1 U
I 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.9 p& Y0 z$ z: {
For example if I have a string attribute called "State" with possible values "PA" and "NC" I know the following equation would work properly: I J% |% e; S, q! x3 v
if (State == 1) then
" X$ \3 ^1 B' `/ f5 Q6 X( G outCon0 = 1;
4 ^, v) ^8 U) L6 r% V4 ]elseif (State == 2) then% c$ i7 X0 a; A. y" H5 Y# H J6 i
outCon0 = 2;
% M& x0 r# j! N/ Q0 K; @else
/ v5 x& \ @7 u( y: d/ h9 P9 ?. V outCon0 = 0;+ g, i- \, q4 Q/ T4 h
However, I want the following to work but don't know how in Extend
: D$ t' r- r8 ^' t- _6 r( ~' Iif (State == "PA") then. ~: w! m2 A- [" h3 h9 U; i
outCon0 = 1;
% F# j8 i2 z( x+ Pelseif (State == "NC") then
. b* F) c/ P( O3 z/ d outCon0 = 2;7 p$ J, t; [$ ?" A1 O7 g4 e/ [
else) Y6 @6 m/ m* `
outCon0 = 0;+ L, K5 r9 j, H/ j7 m7 Z8 f8 L
& Q j4 D- _1 ~ P; F( Y1 U0 i
1 x) n$ {% }+ M9 b* I8 JAnswer: 1 a% I! {* C z6 t9 g
4 B" J" A$ G5 T# R* T
That'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:
1 h/ G7 `$ P" Z* d2 I6 }; T6 N. U% o- m0 l* R3 [
if(SLStringGet("State", State) == "NC") Path = 0;
4 X0 w% y1 Q$ Delse if(SLStringGet("State", State) == "PA") Path = 1;
2 W/ t& L2 n8 J5 B, telse abort;
! J. P o/ ~+ o A: _0 A
- e* W; Q1 }3 II 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. |