Posted By: Matt_UK
Weird problem with strings... - 07/23/10 20:51
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.
Posted By: fangedscorpion
Re: Weird problem with strings... - 07/23/10 21:02
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
Posted By: Matt_UK
Re: Weird problem with strings... - 07/23/10 21:14
Thanks for the reply!
I've just tried your solution, but now I get two "Invalid arguments" errors!
Could this be a bug?
Posted By: DJBMASTER
Re: Weird problem with strings... - 07/23/10 21:43
The string is declared but not initialized. You need the 'str_create' function for that...
STRING* fullpath = str_create("");
Posted By: tD_Datura_v
Re: Weird problem with strings... - 07/23/10 21:50
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.
Posted By: fangedscorpion
Re: Weird problem with strings... - 07/23/10 22:26
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
Posted By: Matt_UK
Re: Weird problem with strings... - 07/23/10 22:38
Thanks for the replies guys! Got it working now thanks to your solutions
. I'll have to remember to try and initialize things if they don't work in the future XD.
Thanks again,
Matt.