1 registered members (AndrewAMD),
1,089
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Strings and Arrays
#289733
09/15/09 08:13
09/15/09 08:13
|
Joined: Jul 2009
Posts: 36
SomebodyNew
OP
Newbie
|
OP
Newbie
Joined: Jul 2009
Posts: 36
|
Hello there, I'm trying to construct the name of an array out of several Strings using str_cat . And then use the resulting string (the name of the array) to modify the array's values. For Example:
var probe_1[4] = { 1, 1, 1, 1};
var probe_2[4] = { 2, 2, 2, 2};
var probe_3[4] = { 3, 3, 3, 3};
var test[4] = { 0, 0, 0, 0};
STRING* first_half = "probe_";
STRING* number;
STRING* second_half = "[3]";
Now I use the following function
function main()
{
str_cpy(number, "1");
str_cat(first_half, number); // "probe_" + "1"
str_cat(first_half, second_half); // "probe_1" + "[3]"
test[3] = first_half;
}
But... it doesn't work. When I check for the value of test[3] it gives me a really huge number (90688). The problem appears to be in the last line. It appears that the string "first_half" is not recognized as an array. I'm stuck here and even after checking the manual I don't know how to work around this. What did I miss? Any help is appreciated.
|
|
|
Re: Strings and Arrays
[Re: DJBMASTER]
#289753
09/15/09 11:43
09/15/09 11:43
|
Joined: Jul 2009
Posts: 36
SomebodyNew
OP
Newbie
|
OP
Newbie
Joined: Jul 2009
Posts: 36
|
Thanks for your answer DJBMASTER. Yes, of course I have completed the lite-c workshops. And I just reread them. Was my problem really that obvious? I thought about using a 3*4 matrice for the values stored in probe_1 to probe_3. Then there is the problem of filling the matrice with numbers (since you can't do it in the definition). I used an algorithm that reads the values of probe_1 and fils them into a new matrice, then does the same for probe_2 and so on.
So, in general, is there a function that allows to write an algorithm that looks for a specific value at a specific position in each array? like: <is probe_1[3] = 5?> and does it for all arrays up to probe_500 (or any big number)? (I would very much prefer to not load all those arrays into one matrice).
Last edited by SomebodyNew; 09/15/09 11:44.
|
|
|
Re: Strings and Arrays
[Re: SomebodyNew]
#289804
09/15/09 17:26
09/15/09 17:26
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
Why can't you fill it with numbers in the definition? A matrix is just a multidimensional array so you will have...
var probe_matrix[3][4] = {1, 1, 1, 1,
2, 2, 2, 2,
3, 3, 3, 3
};
You can use a simple for loop and use if statements to check the value of each index.
Last edited by DJBMASTER; 09/15/09 17:48.
|
|
|
Re: Strings and Arrays
[Re: DJBMASTER]
#289939
09/16/09 12:12
09/16/09 12:12
|
Joined: Jul 2009
Posts: 36
SomebodyNew
OP
Newbie
|
OP
Newbie
Joined: Jul 2009
Posts: 36
|
As far as I know (i hope somebody will correct me here) lite-c doesn't allow you to fill a matrice with numbers in the definition (well it does, but you can't use more than one line. So have fun with something like a 30*40 matrice). That means you have to divide the matrice into arrays. Each line of the matrice is represented by a array. And only now you can use an algorithm that reads the arrays and writes them in the matrice. So you end up with arrays + matrice. While they're basically the same.
Thats why I tried to avaoid using matrices. It does work - but is a major inconvenience.
c#/c++ allow the type of declaration you mentioned.
A sidequestion: is there a way one can display a matrice's values ingame? Like you can do with an array's values. Panel -> digits ... They don't work with multidimensional arrays.
I'm using lite-C in version 7.11.1. They added some things to matrices in version 7.80 i think. But I don't know what it is or if the updates would affect this issue.
Last edited by SomebodyNew; 09/16/09 13:06.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|