Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,089 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Strings and Arrays #289733
09/15/09 08:13
09/15/09 08:13
Joined: Jul 2009
Posts: 36
S
SomebodyNew Offline OP
Newbie
SomebodyNew  Offline OP
Newbie
S

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:
Code:
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
Code:
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. smile

Re: Strings and Arrays [Re: SomebodyNew] #289737
09/15/09 09:32
09/15/09 09:32
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
You can't do that in lite-c. You are trying to evaluate a string so that the compiler see's it as the value at probe_1[3]. What you are actually doing is setting the 3rd position of the test array to the string "probe_1[3]".

Have you completed the lite-c workshops? You need to understand how arrays work before diving into them because they can be quite complex at times.

Re: Strings and Arrays [Re: DJBMASTER] #289753
09/15/09 11:43
09/15/09 11:43
Joined: Jul 2009
Posts: 36
S
SomebodyNew Offline OP
Newbie
SomebodyNew  Offline OP
Newbie
S

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 Offline
Serious User
DJBMASTER  Offline
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...
Code:
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
S
SomebodyNew Offline OP
Newbie
SomebodyNew  Offline OP
Newbie
S

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.

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1