Parsing multiple variable into an array
I'm not even sure if it's possible, but if it is.. would someone reply on this.

pawn Код:
`enum Test{    Var_1[25],    Var_2[25],}new Array[5][Test];new var1 = 1;new var2 = 2;Array[var1(+var2)][Var_(var1)] = var2; // here's where I'm 'stuck'..`
Thanks : ))
You mean something like this?
new a = 1;
then: Var_(a) would be Var_1
a = 2: Var_2 and so on?

Afaik this is not possible in that way. What you could try is a ? condition (dont know how it is called )

you would write (create) Var_(a) like this then:

(a == 1) ? (Var_1) : (Var_2)

This would be expandable for as much values youd like, maybe together with a macro. But i think this is not really what you are looking for, is it?
Quote:
 Originally Posted by Mauzen then: Var_(a) would be Var_1 a = 2: Var_2 and so on?
That's what Im looking for, but can't find an way to do it.. I know it's not possible the way i showed, it's just so others get an example of my question.
Hmm, the ? : stuff would be at least a possibility then.
(condition) ? (when true) : (when false)
Depends on how many different values you would need. Id say 10 would still be okay. You could interleave as much of those conditions as you want, but it gets more and more confusing
Quote:
 Originally Posted by Mauzen Hmm, the ? : stuff would be at least a possibility then. (condition) ? (when true) : (when false) Depends on how many different values you would need. Id say 10 would still be okay. You could interleave as much of those conditions as you want, but it gets more and more confusing
Yeah, confuses me even before it try.

like this?

pawn Код:
`Array[0][var_?var] = var;`
Gives me an warning, 'var_' isn't defined.
In this case it would look like this:

Array[0][(var1 == 1) ? (Var_1) : (Var_2)]

(if var1 == 1, then put Var_1 here, else Var_2)

There are some good examples in the wiki: https://sampwiki.blast.hk/wiki/Control_Structures#.3F:
Took me some time to understand it, too, it is a quite complex structure.
Quote:
 Originally Posted by ****** Just use a 2d array: pawn Код: `enum Test{    Var[2][25],}` Alternatively read up on the memory layout of enums - those arrays are appended sequentially so you can work out offsets in Var_1 which are actually in Var_2.
Already tried, Couldn't get it working though.

pawn Код:
`enum Test{     Var[2][20]; // ' error 001: expected token: "}", but found "[" '}new Array[50][Test]; // 3D array ftw?`
The format would be:
pawn Код:
`enum Test{   Var[2][20]};`
However, you cannot create 3D Arrays inside of enums.
Quote:
 Originally Posted by Grim_ The format would be: pawn Код: `enum Test{   Var[2][20]};` However, you cannot create 3D Arrays inside of enums.
Oh explains it.

Forum Jump:

Users browsing this thread: 1 Guest(s)