Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (7th_zorro, howardR, AndrewAMD), 993 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Weird problem with strings... #334546
07/23/10 20:51
07/23/10 20:51
Joined: May 2010
Posts: 22
M
Matt_UK Offline OP
Newbie
Matt_UK  Offline OP
Newbie
M

Joined: May 2010
Posts: 22
Hi! I am working on a project, which involves the use of strings to allow for future "mods" and easier updating.

I always run into a problem though with strings, heres my code:

function loadLevel(STRING* name);
{
STRING* fullpath = name;
str_cat(fullpath, "\\config.cfg"); // At this line I recieve a "Invalid Arguments in loadLevel" error?
}

function main()
{
loadLevel("map1");
}

Any ideas why this is happening... it seems perfectly acceptable..

Thanks,
Matt.

Re: Weird problem with strings... [Re: Matt_UK] #334548
07/23/10 21:02
07/23/10 21:02
Joined: Jul 2009
Posts: 80
Area 51
F
fangedscorpion Offline
Junior Member
fangedscorpion  Offline
Junior Member
F

Joined: Jul 2009
Posts: 80
Area 51
You cannot equate strings the same way that you can with variables.

Instead to make 2 strings equal you must use:

str_cpy(STRING* name, characters) //the characters are a set of numbers etc enclosed in the "" marks or the name of another string.

for your code you could write:

function loadLevel(STRING* name)
{
STRING* fullpath;
str_cpy(fullpath, name); //this sets fullpath = to the name string
str_cat(fullpath, "\\config.cfg");
}

//rest of your code here

See if that helps


Last edited by fangedscorpion; 07/23/10 21:02.

"Pow! You are dead! Not big suprise!" -Heavy
Re: Weird problem with strings... [Re: fangedscorpion] #334550
07/23/10 21:14
07/23/10 21:14
Joined: May 2010
Posts: 22
M
Matt_UK Offline OP
Newbie
Matt_UK  Offline OP
Newbie
M

Joined: May 2010
Posts: 22
Thanks for the reply!

I've just tried your solution, but now I get two "Invalid arguments" errors!

Could this be a bug?

Re: Weird problem with strings... [Re: Matt_UK] #334552
07/23/10 21:43
07/23/10 21:43
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Code:
STRING* fullpath;


The string is declared but not initialized. You need the 'str_create' function for that...
Code:
STRING* fullpath = str_create("");



Re: Weird problem with strings... [Re: DJBMASTER] #334554
07/23/10 21:50
07/23/10 21:50
Joined: Dec 2005
Posts: 116
T
tD_Datura_v Offline
Member
tD_Datura_v  Offline
Member
T

Joined: Dec 2005
Posts: 116
Code:
function loadLevel(STRING* name);
{
STRING* fullpath = name;
str_cat(fullpath, "\\config.cfg"); // At this line I recieve a "Invalid Arguments in loadLevel" error?
}

function main()
{
loadLevel("map1");
}


Erroneous semicolon after function loadLevel.
"map1" might be an immutable char* const(ant), which might not be passed as a STRING* argument to function loadLevel.


Re: Weird problem with strings... [Re: fangedscorpion] #334558
07/23/10 22:26
07/23/10 22:26
Joined: Jul 2009
Posts: 80
Area 51
F
fangedscorpion Offline
Junior Member
fangedscorpion  Offline
Junior Member
F

Joined: Jul 2009
Posts: 80
Area 51
Try this code then:

function loadLevel(STRING* name)
{
STRING* fullpath = "";//this creates an empty string
str_cpy(fullpath, name); //this sets fullpath = to the name string
str_cat(fullpath, "\\config.cfg");
}


Then add in the main

function main()
{
levelLoad("map_name");
}

I have tried this and it should work

fangedscorpion


"Pow! You are dead! Not big suprise!" -Heavy
Re: Weird problem with strings... [Re: fangedscorpion] #334559
07/23/10 22:38
07/23/10 22:38
Joined: May 2010
Posts: 22
M
Matt_UK Offline OP
Newbie
Matt_UK  Offline OP
Newbie
M

Joined: May 2010
Posts: 22
Thanks for the replies guys! Got it working now thanks to your solutions grin. I'll have to remember to try and initialize things if they don't work in the future XD.

Thanks again,
Matt.


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