[SOLVED] Problem with AGS v2.71RC2 & MI2 Template for 2.7

Started by subspark, Thu 27/10/2005 03:36:25

Previous topic - Next topic

subspark

Here we go again! Sigh.

Here is the error I am getting now that I have upgraded to Release Candidate 2.

Error (line 631): Type missmatch: cannot convert 'const string' to 'string'

This section of my Global script is pretty self explanitory. Its from the MI2 SCUMM GUI template released for AGS 2.7

Code: ags
////////////////////// MODES SETUP ///////////////////////
//////////////////////////////////////////////////////////
//Normal modes:		MODE	"name"	 	AGS	Extension	
//						cursor
//						mode
Ã,  DefineMode(		WALK,		"Walk to",	9,	0);//Line 631. The template uses AGS mode 9 for walk modes, instead of 0.
Ã,  DefineMode(		LOOK,		"Look at",	1,	'l');
Ã,  DefineMode(		TALK,		"Talk to",	3,	't');
Ã,  DefineMode(		PICKUP,	"Pick up",	5,	'p');
Ã,  DefineMode(		OPEN,		"Open",			8,	'o');
Ã,  DefineMode(		CLOSE,	"Close",		8,	'c');
Ã,  DefineMode(		PUSH,		"Push",			8,	's');
Ã,  DefineMode(		PULL,		"Pull",			8,	'y');

//Inventory modes:	MODE	"name"	 	Prepo-	Only	Can	Extension
//						sition	inv.	interact
//								w/ inv
Ã,  DefineInvMode(	USE,	"Use",		"with",	0,	1,	'u');
Ã,  DefineInvMode(	GIVE,	"Give",		"to",		1,	0,	'g');

//*Only inv: 	Means that you can only use that mode followed by an inventory item:
//Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  	USE has 0, because you can USE a hotspot also. However, you can't
//Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  	GIVE a hotspot, you must GIVE an inv. item you already have, therefore
//							GIVE has 1.
//*Can interact	USE has 1, because you could have an inventory item like the 
//Ã,  Ã,  with inv:	"navigator's head" in Monkey Island 1, on which if you click 'USE item'
//		then the item performs some action, instead of putting 'USE item WITH'
//		and waiting for the player to select someting to USE the item WITH.
//		An interaction like "GIVE item" on its own, doesn't make sense, 
//		(because you must GIVE something _TO someone_) so GIVE has 0.

// the button sprites probably deppend on the language being used 	
Ã,  if (Translation("default")){ // if no translation file is being used
//			mode	button	normal	highlighted
//				number	sprite	sprite
Ã,  Ã,  DefineButton(	GIVE,		0,	13,	22); 
Ã,  Ã,  DefineButton(	PICKUP,	1,	14,	23); 
Ã,  Ã,  DefineButton(	USE,		2,	15,	24);
Ã,  Ã,  DefineButton(	OPEN,		3,	16,	25);
Ã,  Ã,  DefineButton(	LOOK,		4,	17,	26);
Ã,  Ã,  DefineButton(	PUSH,		5,	18,	27);
Ã,  Ã,  DefineButton(	CLOSE,	6,	19,	28);
Ã,  Ã,  DefineButton(	TALK,		7,	20,	29);
Ã,  Ã,  DefineButton(	PULL,		8,	21,	30);
Ã,  }
//////////////////////////////////////////////////////////


I hope I don't have to rewrite the majority of the game code.

Darn.

What do you guys think? Any Ideas why it's suddenly giving me hiccups? Ã, :o

strazer

If you're using Beta versions, you have to keep up with the changes:

Quote from: Pumaman on Sun 05/06/2005 23:32:14
Backwards compatibility

In order to maintain backwards compatibility, a new "const" keyword has been added. This applies only to old-style strings, and allows them to interoperate with the new ones. A new-style String can be passed to a function that expects a "const string" (which means that it will not be allowed to change the string's contents), but cannot be passed to a function that expects a "string" (since it could overwrite the string data and mess things up).

So, you may find that any custom functions you have that take a string parameter stop working. If this is the case, change the parameter from "string" to "const string" and that should fix it.

Apologies for the inconvenience, but this is the only way to allow new Strings to interoperate safely with old-style strings.

Try changing the second parameter in the definition and import of the DefineMode and DefineInvMode functions from "string ..." to "const string ...". You probably will have to do that for a bunch of functions.

subspark

#2
so to bring this to practise,
it would go for example:

Code: ags
DefineMode( WALK, "const Walk to", 9, 0);//Line 631. The template uses AGS mode 9 for walk modes, instead of 0.



Or ideally, how would I rewrite this code to work as a new string instead of trying to hack around?
Cheers anyhow

strazer

No. Change

  // global script
  function DefineMode(blah, string blah, ...) {
to
  function DefineMode(blah, const string blah, ...) {

and

  // script header
  import function DefineMode(blah, string blah, ...);
to
  import function DefineMode(blah, const string blah, ...);

etc.

Gilbert

Nope.

There must be a line in the script which declare the function DefineMode(), which would be something like this:

function DefineMode(int Ã, mode, string buffer, int x, int y);

Just change the string to const string:
function DefineMode(int Ã, mode, const string buffer, int x, int y);

Strazer beats me to that, but I'll post anyeay.

subspark

Cheers to the both of you.

Funny though as I never had to state the word string in the actual "" for it to work before, or is this a shining example of the changes that were made between v2.7 and v2.71RC1/2

I know how to fix the problem I'm just slightly confused about the specifics.

Beers!

subspark

#6
Its all good. I only had to add const to several functions.

My only problem now is this part which returns the same error.

Code: ags
// the button sprites probably deppend on the language being used 	
Ã,  if (Translation("default")){ // if no translation file is being used
//			mode	button	normal	highlighted
//				number	sprite	sprite
Ã,  Ã,  DefineButton(	GIVE,		0,	13,	22); 
Ã,  Ã,  DefineButton(	PICKUP,	1,	14,	23); 
Ã,  Ã,  DefineButton(	USE,		2,	15,	24);
Ã,  Ã,  DefineButton(	OPEN,		3,	16,	25);
Ã,  Ã,  DefineButton(	LOOK,		4,	17,	26);
Ã,  Ã,  DefineButton(	PUSH,		5,	18,	27);
Ã,  Ã,  DefineButton(	CLOSE,	6,	19,	28);
Ã,  Ã,  DefineButton(	TALK,		7,	20,	29);
Ã,  Ã,  DefineButton(	PULL,		8,	21,	30);
Ã,  }
//////////////////////////////////////////////////////////


It's weird because DefineButton contains no strings.

Also I tried this:

Code: ags
function Translation(const string language){
Ã,  // checks if the translation passed as parameter is being used. To check if no translation is being used, pass "none" or "default" as parameter.
Ã,  string currentlang;
Ã,  GetTranslationName(currentlang);
 if ((IsTranslationAvailable()==1 && StrCaseComp(currentlang, language)==0) || 
Ã,  Ã,  Ã, (IsTranslationAvailable()==0 && (StrCaseComp("none", language)==0 || StrCaseComp("default", language)==0)))
Ã,  Ã,  Ã,  return 1;
 else return 0;
}


and theres no spot in the following to put a const:

Code: ags
function DefineButton(int mode, int button, int normalbuttonpic, int overbuttonpic){
Ã,  //Define the buttons for a template mode. Call it in game_start for each mode to
Ã,  //set up them all.
Ã,  Tmode[mode].button=button;
Ã,  Tmode[mode].highlightedbutton=overbuttonpic;
Ã,  Tmode[mode].normalbutton=normalbuttonpic;
}


EDIT: Fixed. For anyone elses knowledge I just had to add constÃ,  in the translation part Example:
Code: ags
function Translation(const string language){
in both the global script and the script header:
Code: ags
import function Translation(const string language);


Naturally, adjusting the function_translation part will correct the DefineButton section.

Thanks for all of your help fellas. Much appreciated! Much indeed.

Gilbert

Try changing it to V2.71 style:
function Translation(const string language){
Ã,  // checks if the translation passed as parameter is being used. To check if no translation is being used, pass "none" or "default" as parameter.
Ã,  String currentlang = Game.TranslationFilename;
  if ((IsTranslationAvailable()==1 && currentlang.CompareTo(language)==0) || 
Ã,  Ã,  Ã, (IsTranslationAvailable()==0 && (StrCaseComp("none", language)==0 || StrCaseComp("default", language)==0)))
Ã,  Ã,  Ã,  return 1;
  else return 0;
}


subspark

Wowsers Gilbot!

Could I trouble you long enough to convert the other functions I have?

They include:
Code: ags
function DefineMode(int mode, const string name, int AGSmode, char extension){
Ã,  //Define non-inventory template modes. Call it in game_start for each mode to
Ã,  //set up them all.
Ã,  StrCopy(Tmode[mode].name, name);
Ã,  Tmode[mode].AGSmode = AGSmode;
Ã,  if (extension!=0) Tmode[mode].extension = extension;
}


and

Code: ags
function DefineInvMode(int mode, const string name, const string preposition, int onlyinv, int caninteractwithinv, char extension){
Ã,  //Define inventory template modes. Call it in game_start for each mode to
Ã,  //set up them all.
Ã,  DefineMode(mode, name, 2, extension);
Ã,  StrCopy(Tmode[mode].preposition, preposition);
Ã,  Tmode[mode].onlyinv = onlyinv;
Ã,  Tmode[mode].caninteractwithinv = caninteractwithinv;
}


And finally how would I go about translating this to more native 2.71 style?

Code: ags
import function Translation(const string language);


Thanks for the help Gilbot. Beers!

Elliott Hird

Change const string tmode to String, and use = not strcopy...

subspark

So...

function DefineMode(int mode, String name, int AGSmode, char extension){
Ã,  //Define non-inventory template modes. Call it in game_start for each mode to
Ã,  //set up them all.
Ã,  Tmode[mode].name = name; //Line 160
Ã,  Tmode[mode].AGSmode = AGSmode;
Ã,  if (extension!=0) Tmode[mode].extension = extension;
}

EDIT: God I'm hopeless. That didn't work.

The error reads:
Error (line 160): cannot assign to 'cursormode::name'

Gilbert

Because changing that would probably need you to change other parts of it as well, since I don't know how stuff Tmode[].name, etc. were defined, I can't help you (and I'm not going to download the template).
My opinion is, unless you want to upgrade the whole template, if you can make it to work (with hacks like using const string, and probably some other places where using String is unavoidable), you don't really need to update everything to the newest style.

Elliott Hird

Tell ya what. I'll start coding a good, standard, SCUMM template for ags2.71.

cjhrules

#13
Quote from: subspark on Thu 27/10/2005 05:11:41

EDIT: Fixed. For anyone elses knowledge I just had to add constÃ,  in the translation part Example:
Code: ags
function Translation(const string language){
in both the global script and the script header:
Code: ags
import function Translation(const string language);


Naturally, adjusting the function_translation part will correct the DefineButton section.

Thanks for all of your help fellas. Much appreciated! Much indeed.

This doesnt work. I changed the translation part but now I get "variable translation is already defined"

Need help with this.
I use Foa template v2 and ags 2.71. I have fixed all the other problems but I cant get passed this one. Should I remove the translate function altogether?

/Calle

subspark

Would you care to export your fixed version as a template for the rest of us?

Good on you pal. Nice coding!

SMF spam blocked by CleanTalk