Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
2 registered members (Quad, AndrewAMD), 1,007 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
STRING* in struct problem #291604
09/26/09 17:29
09/26/09 17:29
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline OP
Senior Member
Razoron  Offline OP
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
Me again...

I defined a struct:

Code:
typedef struct
{
        STRING*script;
	MAP*map;
} LEVEL;



and initialized the STRING at the beginning:

Code:
LEVEL*lvl_K={script="#20";}



Now, i want to copy something in it:

Code:
STRING*str=str_create("hello");
str_cpy(lvl_K.script,str);



When i try to copy it, the Engine says: Invalid Arguments.

EDIT:

When i add
Code:
lvl_k.script=str_create("#20");


before i copy something in it, the Engine doesn't give any errors and the string contains "hello". But text(
Code:
TEXT*txt_1=
{
	pos_x=100;
	pos_y=100;
	layer=2;
	font="Courier#25b";
	string=lvl_K.script;
}

) still shows "#20". Not an empty contant of 20 characters, simply #20. Why?

Help me!

Last edited by Razoron; 09/26/09 17:52.
Re: STRING* in struct problem [Re: Razoron] #291609
09/26/09 18:21
09/26/09 18:21
Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
GorNaKosh Offline
Junior Member
GorNaKosh  Offline
Junior Member

Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
Have no idea, but this example I made quikly, works perfect for me:
Code:
#include <acknex.h>

typedef struct LEVEL {
	STRING *script;
	var xyz;
} LEVEL;

LEVEL *testLvl = { script = "#20"; xyz = 0; }

void main() {
	
	//getting the string into the struct you have two options
	//ONE
	STRING *testStr = str_create("test-script");
	testLvl.script = str_create("#20");
	str_cpy(testLvl.script, testStr);
	str_remove(testStr);

	//TWO
	STRING *testStr = str_create("test-script");
	testLvl.script = testStr;
	
	wait(1);
	error(testLvl.script);
}



Maybe post a little bit more of the whole code!?

greez
Gor Na Kosh

Last edited by GorNaKosh; 09/26/09 18:26.
Re: STRING* in struct problem [Re: GorNaKosh] #291646
09/27/09 08:31
09/27/09 08:31
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline OP
Senior Member
Razoron  Offline OP
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
But now, you add a TEXT:

Code:
#include <acknex.h>

typedef struct LEVEL {
	STRING *script;
	var xyz;
} LEVEL;

LEVEL *testLvl = { script = "#20"; xyz = 0; }

TEXT*txt=
{
	pos_x=10;
	pos_y=10;
	flags=SHOW;
	font="Courier#25b";
	string=testLvl.script;
}

void main() {
	
	//getting the string into the struct you have two options
	//ONE
	STRING *testStr = str_create("test-script");
	testLvl.script = str_create("#20");
	str_cpy(testLvl.script, testStr);
	str_remove(testStr);

	//TWO
	STRING *testStr = str_create("test-script");
	testLvl.script = testStr;
	
	wait(1);
	error(testLvl.script);
}



And the TEXT shows "#20".

Re: STRING* in struct problem [Re: Razoron] #291669
09/27/09 12:15
09/27/09 12:15
Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
GorNaKosh Offline
Junior Member
GorNaKosh  Offline
Junior Member

Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
oky, got it. Seems like the TEXT doesn't refreshs the string... think you have to copy the new string into the TEXT-object after having some changes always:
Code:
#include <acknex.h>

typedef struct LEVEL {
	STRING *script;
	var xyz;
} LEVEL;

LEVEL *testLvl = { script = "#20"; xyz = 0; }

TEXT *txtTest=
{
	pos_x=10;
	pos_y=10;
	font="Courier#25b";
	strings = 1;
	flags = SHOW;
}

void main() {

	//change the string in the LEVEL-struct
	STRING *testStr = str_create("test-script");
	testLvl.script = testStr;
	
	//apply new string to the visible TEXT-object
	str_cpy((txtTest.pstring)[0], testLvl.script);
}


http://www.conitec.net/beta/atext-string.htm

Re: STRING* in struct problem [Re: GorNaKosh] #291672
09/27/09 12:31
09/27/09 12:31
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Also, "#20" is in C a char* and not a STRING*. Thats why the first attempt gave you invalid arguments because the target string of str_cpy must be really a STRING*, a char* wont work, it only works in functions were it does not matter if the argument is a STRING* or char*.

Re: STRING* in struct problem [Re: Tobias] #291686
09/27/09 14:34
09/27/09 14:34
Joined: May 2009
Posts: 445
Peine, Germany
Razoron Offline OP
Senior Member
Razoron  Offline OP
Senior Member

Joined: May 2009
Posts: 445
Peine, Germany
Thank you all laugh


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