将字符串插入数组 - PAWN脚本

时间:2013-06-14 19:39:26

标签: arrays merge string-concatenation pawn

我试图通过将一个变量插入到多个数组来减少我的文件行。所以我想要一个字符串或一个数组变量,如下所示:

new combomeals[] = { 
    3025101, 3025100, 3003000, 3025002, 3030101, 3025001, 3025000, 3021602, 3031402, 3020100, 
    3031401, 3031400, 3031302, 3020242, 3031301, 3031300, 3021702, 3021701, 3021700, 3020602, 
    3021601, 3030100, 3021600, 3021502, 3021501, 3020201, 3021500, 3020150, 3020502, 3020501, 
    3020500, 3001802, 3001801, 3001800, 3001702, 3001701, 3001700, 3011602, 3011601, 3011600, 
    3011502, 3020202, 3011501, 3011500, 3011232, 3011231, 3011202, 3011201, 3010602, 3010601, 
    3010600, 3010902, 3010901, 3010900, 3011102, 3011101, 3011100, 3011002, 3011001, 3011000, 
}

它实际上要比这长得多,但是为了解释我缩短了它...我想把combomeals []放到其他数组中。以下不起作用,但你会明白:

new first_array[] = { 
    1, 
    2, 
    3,
    combomeals[], 
}

new second_array[] = { 
    4, 
    5, 
    6,
    combomeals[], 
}

new third_array[] = { 
    7, 
    8, 
    9,
    combomeals[], 
}

最终目标是将第一个数组放入其他几个数组中。如果这有意义,请告诉我,如果你能帮忙的话!

谢谢!

1 个答案:

答案 0 :(得分:3)

您无法以尝试的方式扩展数组。假设new已被别名为整数类型,则如果列表中的所有元素都是相同类型,则编译器将仅接受first_array的初始化列表。但是列表的最后一个元素是语法错误,因为combomeals是一个数组,combomeals[]不属于初始化列表。

同样适用于second_arraythird_array

您可以通过将combomeals中的数字放入宏中来完成类似的操作:

#define COMBOS \
3025101, 3025100, 3003000, 3025002, 3030101, 3025001, 3025000, 3021602, 3031402, 3020100, \
3031401, 3031400, 3031302, 3020242, 3031301, 3031300, 3021702, 3021701, 3021700, 3020602, \
3021601, 3030100, 3021600, 3021502, 3021501, 3020201, 3021500, 3020150, 3020502, 3020501, \
3020500, 3001802, 3001801, 3001800, 3001702, 3001701, 3001700, 3011602, 3011601, 3011600, \
3011502, 3020202, 3011501, 3011500, 3011232, 3011231, 3011202, 3011201, 3010602, 3010601, \
3010600, 3010902, 3010901, 3010900, 3011102, 3011101, 3011100, 3011002, 3011001, 3011000,

new combomeals[] = { COMBOS };

new first_array[] = { 1, 2, 3, COMBOS };
new second_array[] = { 4, 5, 6, COMBOS };
new third_array[] = { 7, 8, 9, COMBOS };

如果编译器在处理长源代码行时遇到问题,则可能需要将COMBOS分开。它不太方便,但只需要c89编译器来支持509字节长的源文件。

#define COMBOS1 \
3025101, 3025100, 3003000, 3025002, 3030101, 3025001, 3025000, 3021602, 3031402, 3020100, \
3031401, 3031400, 3031302, 3020242, 3031301, 3031300, 3021702, 3021701, 3021700, 3020602, \
3021601, 3030100, 3021600, 3021502, 3021501, 3020201, 3021500, 3020150, 3020502, 3020501
#define COMBOS2 \
3020500, 3001802, 3001801, 3001800, 3001702, 3001701, 3001700, 3011602, 3011601, 3011600, \
3011502, 3020202, 3011501, 3011500, 3011232, 3011231, 3011202, 3011201, 3010602, 3010601, \
3010600, 3010902, 3010901, 3010900, 3011102, 3011101, 3011100, 3011002, 3011001, 3011000

new combomeals[] = {
    COMBOS1,
    COMBOS2,
};

new first_array[] = {
    1, 2, 3,
    COMBOS1,
    COMBOS2,
};

/* ...etc... */

如果您的C编译器不符合,您可能需要进一步细分。