Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (TipmyPip, AndrewAMD, NewbieZorro), 15,207 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
listing strings in rows/Liste aus Strings #132580
05/29/07 19:05
05/29/07 19:05
Joined: May 2007
Posts: 19
Z
Zalon Offline OP
Newbie
Zalon  Offline OP
Newbie
Z

Joined: May 2007
Posts: 19
Hi Board,

I like to create a kind of ingame address book, showing the addresses the player collected in some rows and add a function to filter the entries later on.

That's the idea, but it seems I've done something terribly wrong, as there are massive problems occuring, including some crashes of the editor.

Maybe somebody's having a good idea or some code-snippets?

What I've coded yet:

First of all, I created a struct that will contain the names and addresses. Simplified, this struct looks like this:
struct { char name; char street; var number;} data;
DATA* addressbook;

Storing some information using addressbook.name, addressbook.street = etc.. was simple.

To display the information onto the screens, I defined some TEXT*-panels, one for the row of names, one for the row of streets etc.
So there are three strings now, called name_string, street_string, number_string.

Now I wanted to copy the information out of the struct into the strings, seperated by "\n" for the new lines, having a string for each row.

But that didn't work.
name_string = addressbook.name as a test will crash the editor.

My first idea, to use a while-loop doesn't work either.

while(i)
name_string = str_cat(name_string, addressbook.name);


I've got that feeling, that there has to be a much easier way...

So any help will be appreciated!! Thanks!

---------------------

Hallo,

ich möchte gerne ein Ingame Adressbuch erstellen, bei dem dem Spieler die bereits gefundenen Orte und Personen in Reihen aufgelistet werden. Später soll eventuell eine Filterfunktion dazukommen. Soweit die Idee, jedoch scheine ich da etwas falsch zu machen.

Ich hoffe dass mir jemand mit einer guten Idee oder ein paar Zeilen Code weiterhelfen kann.

Bisher habe ich folgendes gemacht:

Als erstes habe ich eine Struct erstellt, in der die Namen und Adressen gespeichert werden sollen. Vereinfacht ausgedrückt, sieht diese so aus:

struct looks like this:
struct { char name; char street; var number;} data;
DATA* addressbook;

Die Informationen mittels addressbook.name, addressbook.street = etc.. einzuspielen war kein Problem.

Um später die Adressen in Reihen ausgeben zu lassen, habe ich drei TEXT*-panels, pro Reihe eine, erstellt.
Die dazugehörigen Strings, name_string, street_string, number_string, habe ich auch definiert.

Jetzt wollte ich die Informationen aus der Struct in die Strings kopieren, jeweils mit einem Zeilenumbruch getrennt. Damit hätte ich dann pro Reihe einen String.

Aber das funktioniert bislang nicht.

name_string = addressbook.name als Testversion bringt den Editor zum Absturz.

Auch meine erste Idee, eine While-loop zu nutzen klappt nicht.

while(i)
name_string = str_cat(name_string, addressbook.name);

Ich habe das Gefühl, es muss auch einfacher gehen...
Für Hilfe bin ich dankbar!

Last edited by Zalon; 05/29/07 19:15.
Re: listing strings in rows/Liste aus Strings [Re: Zalon] #132581
05/31/07 10:55
05/31/07 10:55
Joined: Jul 2000
Posts: 28,024
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,024
Frankfurt
"Char" is just an 8 bit number. So, it's not

struct { char name; char street; var number;} data;

but something like

struct { char name[32]; char street[32]; var number;} data;

Of course, there are probably more bugs in your first attempt. The best way to find them is using the debugger and walking step by step through your code while observing the strings and values.

Re: listing strings in rows/Liste aus Strings [Re: jcl] #132582
05/31/07 14:14
05/31/07 14:14
Joined: May 2007
Posts: 19
Z
Zalon Offline OP
Newbie
Zalon  Offline OP
Newbie
Z

Joined: May 2007
Posts: 19
Thanks for the reply.

I already used debugger and breakpoints but couldn't find a solution.

Maybe a dumb question, but char name [32] will create an array (in the struct??), won't it? Will that solve my problem of crashes while transforming them into strings? (and if it does: why?)

Is there a way to define strings in the struct? Obviously struct {string test} does not work...

Whew, quite many questions. Hope you (or anyone else?) might help.

Last edited by Zalon; 05/31/07 14:29.
Re: listing strings in rows/Liste aus Strings [Re: Zalon] #132583
05/31/07 16:16
05/31/07 16:16
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
a string basically is an array of letters.

An A6/7 STRING carries a bit more information, but the string itself is nothing else than an array of a char (STRING->chars)

Re: listing strings in rows/Liste aus Strings [Re: FBL] #132584
05/31/07 19:46
05/31/07 19:46
Joined: May 2007
Posts: 19
Z
Zalon Offline OP
Newbie
Zalon  Offline OP
Newbie
Z

Joined: May 2007
Posts: 19
Thanks.
That means, by defining an array of chars, I create a string?

I'm always wondering where to find thie kind of information, neither the Lite-C tutorial, nor the SED-manual deal with such things...

Last edited by Zalon; 05/31/07 19:49.
Re: listing strings in rows/Liste aus Strings [Re: Zalon] #132585
05/31/07 21:43
05/31/07 21:43
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
You create a string as defined in standard C - but an A6 STRING is an own struct which carries some more information.

Use str_create("...") to create an A6 STRING.

A6 string function like str_cpy or str_cat (note the _) expect as target a STRING and as source a ponter to a char array or a STRING as well.

For copying around char arrays you'll need to add your own APIcalls for strcpy, strcat, strlen...

This is what the A6 STRING struct looks like. The char array is referenced by "chars":
Code:

typedef struct STRING {
C_LINK link;
char *chars; // pointer to null terminated string
long length; // allocated length of string
long flags; // last bit 0 = don't save, 1 = save string at SAVE/LOAD
} STRING;



Re: listing strings in rows/Liste aus Strings [Re: FBL] #132586
06/01/07 13:24
06/01/07 13:24
Joined: May 2007
Posts: 19
Z
Zalon Offline OP
Newbie
Zalon  Offline OP
Newbie
Z

Joined: May 2007
Posts: 19
Thanks again my friend.

Thing I got that: A A6 string is a kind of char.

But I still don't understand the link between the string definiton and a char array. Why should I change my own struct definition to include char arrays instead of pure chars?

Additionally you mentioned another point. You wrote, I'll have to add my "own APIcalls for strcpy, strcat...".

First of all, just to see whether I really understand you: As A6's strings are something special and these functions expect not only a string but a special form, namely a "A6 string", they wouldn't work with a "normal" (that means a standard C) string.
Is that right?

But as I should deal with char-arrays (see above, I still don't get the why), I have to find a way to rewrite these functions to accept these inputs..?

To make things worse, I have no idea how to change the APIcalls as I don't even know how they look like. I'll have a look at the manual immediately, maybe there are some hints concerning these ominous calls, but just in the case I don't find something appropriate - in fact appropriate for me - how could I start here?

Phew. That's becoming real tough for me.

Last edited by Zalon; 06/01/07 13:27.
Re: listing strings in rows/Liste aus Strings [Re: Zalon] #132587
06/01/07 16:00
06/01/07 16:00
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
I think you roughly got it.

Easiest way is to work with STRINGs

str_cpy and the like can copy char arrays into STRINGs, or STRINGs into STRINGs, but not char arrays into char arrays.

For using native C strcpy which can do the later thing (and nothing else) you should be able to find examples in the Contributions forum. People have added these functions before - it should just be a copy&paste issue. But probably they are already available by default in the latest lite-C release. I've only tested with a rather old version.

Re: listing strings in rows/Liste aus Strings [Re: FBL] #132588
06/01/07 17:29
06/01/07 17:29
Joined: May 2007
Posts: 19
Z
Zalon Offline OP
Newbie
Zalon  Offline OP
Newbie
Z

Joined: May 2007
Posts: 19
Okay, I will search the forum for the modified str_cpy.

Sorry to bother you again, but two questions remain.

"Eastiest way ist to work with strings", I agree on that. But I cannot define strings in structs, can I?
(That's why I'm using these char arrays that work like strings)

Additionally, it seems to me that str_cpy is not capable of copying structs or struct-arrays - consisting of chars to be precise - into strings. At least the editor crashes as soon as I'm trying to make a
str_cpy(teststring, struct.name_of_char)

Re: listing strings in rows/Liste aus Strings [Re: Zalon] #132589
06/01/07 17:35
06/01/07 17:35
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
structs can contain STRINGs. This is no problem.

As to your copy problem:

struct test{
char charArray[5];
};

STRING mySTR;
struct test testCharStruct;
mySTR = str_create("");

testCharStruct.charArray[0]= 't';
testCharStruct.charArray[1]= 'e';
testCharStruct.charArray[2]= 's';
testCharStruct.charArray[3]= 't';
testCharStruct.charArray[4]= '\0'; /*string termination*/

str_cpy(mySTR, testCharStruct.charArray);

printf("%s", mySTR->chars);

untested. Probably won't work because I did some stupid mistake... but I hope you get the idea.

Last edited by Firoball; 06/01/07 17:41.
Page 1 of 3 1 2 3

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

Gamestudio download | 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