Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Reno Caspain on Tue 01/08/2006 20:39:54

Title: upgrading to 2.71
Post by: Reno Caspain on Tue 01/08/2006 20:39:54
I'm upgrading my old game project to 2.71, and have changed string variables to const string in the main script and script header. However, I still get the same error in the following piece of script.

Error line 125, cannot convert const string to string

/**/function RemoveExtension(const string location){
/**/  //removes the extension of a string 
/**/  int length=StrLen(location);
/* (This is the line 125)*/  if (Extension(location)!=0) StrSetCharAt(location,length-2,0);
/**/  return location;

Any ideas how to fix this?
Title: Re: upgrading to 2.71
Post by: Rui 'Trovatore' Pires on Tue 01/08/2006 20:42:04
I appreciate this may not be the answer you're looking for, but have you tried convert all "string"s to the new "String"s and using them instead of trying to make the old ones work?

Also, just for sake of completion: "Enfore new-style strings" is off if you ain't gonna use them, right?
Title: Re: upgrading to 2.71
Post by: monkey0506 on Tue 01/08/2006 21:12:38
I'd venture to say that the problem here is the function Extenstion is defined as Extension(string), right?

Presumably you would have access to change the string in this context, however the parameter you have passed for RemoveExtension is const, which means it can't be edited. So trying to pass a const string parameter to a function with a string parameter fails because that would mean that the const status would be lost and the parameter could be edited even though it was supposed to be const.

Solutions:

a) Make the RemoveExtension parameter a regular string instead of a const string (this means that new-style Strings cannot be passed through the function).
b) Make the parameter for Extension a const string (presumably this isn't possible because you want to edit the string).
c) Upgrade to new-style Strings.*

*Best Value. :=

Actually...new-style Strings are more user-friendly. Although they can create some "null pointer referenced!!!111" issues, they are much nicer IMO.

If you decide you want to upgrade you can just use a String for the parameter (although you cannot pass old-style strings through these types of functions, you could use String.Format("%s", oldstylestr) as the parameter).
Title: Re: upgrading to 2.71
Post by: SSH on Tue 01/08/2006 21:56:53
That looks like some of Proskrito's SCUMM template to me: try using my updated version, or at least comparing the code.
Title: Re: upgrading to 2.71
Post by: Reno Caspain on Wed 02/08/2006 07:14:39
I modified the script like this:

/**/function RemoveExtension(string location){ // originally string
/**/  //removes the extension of a string 
/**/  int length=StrLen(location);
/**/  if (Extension(location)!=0) StrSetCharAt(location,length-2,0);
/*(this is line 126*/  return location;

That seemed to fix the problem with line 125, but now I get the error "cannot convert string to int" from line 126.

This is indeed an old proskritos template, but I have already made 37 rooms worth of game on it so I'd like to avoid rewriting majority of my code, if possible. Or is there some way to translate the game to the new template?
Title: Re: upgrading to 2.71
Post by: Alynn on Wed 02/08/2006 07:44:03
where you are returning the string... where in the code are you calling RemoveExtention

if you have

int x = RemoveExtention(someString)

you will get that error since RemoveExtention is returning a string not an int. But I would think you would get it at the place it was called not in the function itself...

Actually doesnt StrSetCharAt return a string anyway so you would need to have location = StrSetCharAt(location, lenght-2, 0);

The manual isn't much help since StrSetCharAt was obsolete and I don't have a version previous to 2.71 to go back to.

Title: Re: upgrading to 2.71
Post by: monkey0506 on Wed 02/08/2006 14:18:14
No...the problem is that function is internally defined as int. So if you try to return a string it would generate that error. Just change "function RemoveExtension" to "string RemoveExtension".

[EDIT:]

And no, StrSetCharAt does NOT return a string. It directly modifies the string passed as the first parameter. You musn't confuse old-style string functions with the new-style String functions (String.ReplaceCharAt returns a modified String).
Title: Re: upgrading to 2.71
Post by: Reno Caspain on Wed 02/08/2006 16:50:13
Thanks monkey_5_6, that fixed it! Next problem is again the "cannot convert const string to string" on the line 145.

/**/function MouseLocationName(const string buffer){ //oli function
/**/  //gets the name of what is under the cursor
/**/ int invitem;
/**/ invitem=GetInvAt(mouse.x,mouse.y);
/*(line 145)*/ if (invitem>=0) GetInvName(invitem,buffer); // if its a inv item
/**/ else GetLocationName(mouse.x,mouse.y,buffer);
/**/ return buffer;
/**/}

These problems ought to start repeating themselves at some point, but until then, what seems to be the problem this time?
Title: Re: upgrading to 2.71
Post by: monkey0506 on Wed 02/08/2006 17:10:09
Once again you're working with an old-style string function.

GetInvName modifies the string parameter (it's not a const string parameter), so you can't pass a const string through the function.

You'll have to change it to a string parameter for MouseLocationName instead of const string, and change "function" to "string" (the problem here is that, interestingly enough returning a string from a "function" used to work (probably because it returned a char[] which it read as an int[]? not completely sure), however there has been type checking implemented since so it doesn't work now).
Title: Re: upgrading to 2.71
Post by: Pumaman on Wed 02/08/2006 18:21:35
Generally, if you're upgrading a function like that, it's best to completely convert it to new-style Strings to make it more readable. However if that's part of a template, it might be worth checking if a newer version of the template is available.