简体   繁体   English

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

[英]Insert string into array - PAWN script

I am trying to cut down my file lines by having one variable to insert into several arrays. 我试图通过将一个变量插入到多个数组来减少我的文件行。 So I'd like to have a string, or an array variable, such as the following: 所以我想要一个字符串或一个数组变量,如下所示:

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, 
}

It's actually much longer than that, but I shortened it for the explanation... I want to take combomeals[] and put that into other arrays. 它实际上要比这长得多,但是为了解释我缩短了它...我想采用combomeals []并把它放到其他数组中。 The following does not work, but you will get the idea: 以下不起作用,但你会明白:

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

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

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

The end goal is to put the first array into several other arrays. 最终目标是将第一个数组放入其他几个数组中。 Please let me know if this makes sense and if you are able to help! 如果这有意义,请告诉我,如果你能帮忙的话!

Thank you! 谢谢!

You cannot extend an array in the way you are attempting. 您无法以尝试的方式扩展数组。 Assuming that new has been aliased to an integral type, then the compiler will only accept the initializer list for first_array if all the elements in the list are the same type. 假设new已被别名为整数类型,那么如果列表中的所有元素都是相同类型,则编译器将仅接受first_array的初始化列表。 But the last element of the list is a syntactic error, as combomeals is an array, and combomeals[] doesn't belong in an initializer list. 但是列表的最后一个元素是语法错误,因为combomeals是一个数组,而combomeals[]不属于初始化列表。

Similarly for the second_array and third_array . 类似地,对于second_arraythird_array

You can accomplish something similar by putting the numbers in combomeals into a macro instead: 您可以通过将数字中完成类似的东西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 };

If your compiler has trouble dealing with a long source line, you may have to split COMBOS apart. 如果编译器在处理长源代码行时遇到问题,则可能需要拆分COMBOS It is less convenient, but a c89 compiler is only required to support a source file length 509 bytes long. 它不太方便,但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... */

You may need to further break down the lines if your C compiler is non-conforming. 如果您的C编译器不符合要求,您可能需要进一步细分这些行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM