Gamestudio Links
Zorro Links
Newest Posts
Why Zorro supports up to 72 cores?
by 11honza11. 04/26/24 08:55
M1 Oversampling
by 11honza11. 04/26/24 08:32
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (VoroneTZ, Quad, EternallyCurious, 1 invisible), 844 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
[Solved] Displaying an array of strings. #456791
12/10/15 02:17
12/10/15 02:17
Joined: Nov 2014
Posts: 24
ME
H
Hawthourne Offline OP
Newbie
Hawthourne  Offline OP
Newbie
H

Joined: Nov 2014
Posts: 24
ME
Greetings, I have been exploring arrays a bit in the context of making an inventory. It seems to me that a relatively simple way to do this is by building a string array and then displaying it, most likely with a text box. The gamestudio manual, however, is fairly scarce on its treatment of String arrays, just making some mention of how they are similar to variable arrays.

With this in mind, I tried to directly define an array using STRING* filler[100]. The script is accepts this notation, but when I try to access an entry of it like I would a variable array (arrayname[entrynumber]) I get a launch error. The only message I am given is a ^before the name of the array entry I was trying to pull.

Am I not able to directly define an array like this, rather I have to manually enter in the various string into a text and use that as the array? My current project is displaying a series of variables, so I was going to translate each entry of the variable array over to an entry of the string array. Is there a better path to take?

Bonus: Also, I placed a vec_set(textname.blue,vector(100,100,100)); into my main function to change the text's color, but it remained white. Any ideas what is up with that?

Thanks for any assistance.

Last edited by Hawthourne; 12/10/15 22:58.
Re: Displaying an array of strings. [Re: Hawthourne] #456793
12/10/15 04:51
12/10/15 04:51

M
Malice
Unregistered
Malice
Unregistered
M



God wishes lite-c work in this c++ way

Code:
STRING* filler[100]
TEXT* OBJECT TO DISPLAY STRINGS <--- See manual
usually provide links but the bottles got me...

fucntion this()
{
int arrayi[100];
.... syntex fills array
int i=0;
for(i=0;i<100;i++)
{
str_for_num(filler[i],arrayi[i]
}
}



I am
Mal
Peace love and fun programming

Last edited by Malice; 12/10/15 04:54.
Re: Displaying an array of strings. [Re: ] #456794
12/10/15 04:52
12/10/15 04:52

M
Malice
Unregistered
Malice
Unregistered
M



Rest of your post is lost to my drunkenness... Thnk night

Re: Displaying an array of strings. [Re: ] #456797
12/10/15 06:31
12/10/15 06:31
Joined: Apr 2015
Posts: 20
Vietnam
F
Florastamine Offline
Newbie
Florastamine  Offline
Newbie
F

Joined: Apr 2015
Posts: 20
Vietnam
You have to replace STRING *filler[] with a pointer to pointer:
Code:
#include <acknex.h>

#define N 10

int main(void)
{
	STRING **array = (STRING *) sys_malloc(sizeof(STRING) * N);
	
	int i = 0;
	for(; i < N; i++)
	    array[i] = str_create(str_printf(NULL, "This is string #%i", i));
	
	for(i = 0; i < N; i++)
	    printf("%s", _chr(array[i]));
	    
	return 0;
}



Another way would be using TEXT.

Quote:
Also, I placed a vec_set(textname.blue,vector(100,100,100)); into my main function to change the text's color, but it remained white. Any ideas what is up with that?


You have to "tell" Acknex that the text object can be colored, by passing an additional "LIGHT" flag:

Code:
#include <acknex.h>

TEXT *text =
{
	strings = 1;
	string("Hello!");
	
	font = "Arial#25b";
	
	flags = SHOW | LIGHT;
}

int main(void)
{
	random_seed(0);
	
	while( !key_esc )
	{
		vec_set(text.blue,vector(random(255.0), random(255.0), random(255.0)));
		wait( -0.5 );
	}
	return 0;
}


Last edited by Florastamine; 12/10/15 06:32. Reason: wrong tag >.<
Re: Displaying an array of strings. [Re: Florastamine] #456800
12/10/15 08:02
12/10/15 08:02
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
You will display this text, so why not use a text directly...
Define a text and follow the manual examples:
Code:
TEXT* inventory_text =	
{
    layer = 1;
    pos_x = 10;
    pos_y = 10;
    strings = 100;
    flags = LIGHT | SHOW;
}



Now, to access individual strings from this text use:
Code:
(inventory_text.pstring)[0]


And I suggest never try to modify this directly. Always use str_cpy or you can get in a lot of trouble without understanding where your error is grin
Code:
str_cpy((inventory_text.pstring)[0],"Short sword");
...
str_cpy((inventory_text.pstring)[1],axeName_str);



Originally Posted By: "Florastamine"
You have to replace STRING *filler[] with a pointer to pointer:

Your answer is great, but...
If he's new to this, I doubt he'll understand what a pointer to pointer is laugh I'm not new, but I just scratched the surface of C++, so even I get confused sometimes...


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Displaying an array of strings. [Re: EpsiloN] #456815
12/10/15 22:58
12/10/15 22:58
Joined: Nov 2014
Posts: 24
ME
H
Hawthourne Offline OP
Newbie
Hawthourne  Offline OP
Newbie
H

Joined: Nov 2014
Posts: 24
ME
Thanks, I got it now. I guess there is a difference between array.pstring[1] and (array.pstring)[1], who would have known? XD

I also loled at Malice's reply,

Re: Displaying an array of strings. [Re: Hawthourne] #456818
12/11/15 05:52
12/11/15 05:52

M
Malice
Unregistered
Malice
Unregistered
M



Quote:
I also loled at Malice's reply,


I am quite ridiculous, for sure!
Quote:
If he's new to this, I doubt he'll understand what a pointer to pointer is laugh I'm not new, but I just scratched the surface of C++, so even I get confused sometimes...


In this usage, it's bit complex for more reasons then pointer to a pointer.
Quote:
STRING **array = (STRING *) sys_malloc(sizeof(STRING) * N);


However the idea of pointer to pointer is not difficult. As In player=my; when written clean in lite-c, is simply a pointer-to-a-pointer, not a copy of the object. An address to a address, but more a copy of a memory address.

But perhaps, my understanding is just poor, in this matter and C++.

Mal

Last edited by Malice; 12/11/15 05:53.
Re: Displaying an array of strings. [Re: Florastamine] #456830
12/11/15 16:26
12/11/15 16:26
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Originally Posted By: Florastamine

Code:
STRING **array = (STRING *) sys_malloc(sizeof(STRING) * N);



This code line is wrong. It allocates N times the length of a STRING struct!

It should be:
Code:
STRING **array = (STRING**) sys_malloc(sizeof(STRING*) * N);



that allocates N times the length of a pointer to a STRING struct.

Salud!

Re: Displaying an array of strings. [Re: txesmi] #456837
12/12/15 04:18
12/12/15 04:18
Joined: Apr 2015
Posts: 20
Vietnam
F
Florastamine Offline
Newbie
Florastamine  Offline
Newbie
F

Joined: Apr 2015
Posts: 20
Vietnam
Originally Posted By: txesmi
Originally Posted By: Florastamine

Code:
STRING **array = (STRING *) sys_malloc(sizeof(STRING) * N);



This code line is wrong. It allocates N times the length of a STRING struct!

It should be:
Code:
STRING **array = (STRING**) sys_malloc(sizeof(STRING*) * N);



that allocates N times the length of a pointer to a STRING struct.

Salud!


Yeah, I forgot about the extra asterisk! Because it's a pointer to pointer, you should allocate memory for the pointers.

Thanks for pointing it out!

Last edited by Florastamine; 12/12/15 04:19.
Re: Displaying an array of strings. [Re: Florastamine] #458825
04/01/16 07:16
04/01/16 07:16
Joined: Jun 2010
Posts: 212
tagimbul Offline
Member
tagimbul  Offline
Member

Joined: Jun 2010
Posts: 212
is this correct?
Code:
STRING **array = (STRING**) sys_malloc(sizeof(STRING*) * N);
...

array[1] = "hello";



can i use array with [] ?


meine website mit 3dgs sachen =) //noch nicht ganz umgebaut ^^"
http://flashbreaker.com/home.html
und mein YT channel mit diversen game entwicklungs videos, vor allem shader zeugs
https://www.youtube.com/user/tagimbul/videos
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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