[SOLVED] Cannot convert string to int - but I'm not ?

Started by bx83, Fri 02/02/2018 07:41:43

Previous topic - Next topic

bx83

I'm sure I'm missing something really, really obvious. Here's the code:

in GlobalScript:
Code: ags

function CheckLoop (this Character*)
{
	if (this.Loop==0) { return "eDirectionDown"; }
	if (this.Loop==1) { return "eDirectionLeft"; }
	if (this.Loop==2) { return "eDirectionRight"; }
	if (this.Loop==3) { return "eDirectionUp"; }
	if (this.Loop==6) { return "eDirectionDownLeft"; }
	if (this.Loop==7) { return "eDirectionUpLeft"; }
	if (this.Loop==4) { return "eDirectionDownRight"; }
	if (this.Loop==5) { return "eDirectionUpRight"; }
}


First, this function takes the loop of an 8-directon character, then returns a String depending on what it is.
Yes, I checked this was in the header: all correct.

In OLD_ROOM:
Code: ags

    savex=cJulius.x;                           //save character's current X position  
    savey=cJulius.y;                           //save character's current Y position
    savedirection=cJulius.CheckLoop();         //get direction of character as String, and save it also
    cJulius.ChangeRoom(NEW_ROOM, 2000, 2000);  //change to new room


This saves the position in a room to temporary variables (savedirection is a String), and then changes to a new room NEW_ROOM, with the character (cJulius) off-screen (background is 1024x768).

In NEW_ROOM:
Code: ags

cJulius.ChangeRoom(OLD_ROOM, savex, savey, savedirection);


When we go *back* to OLD_ROOM with the above command, the temporary storage of the character's last position is restored, and we travel back to room OLD_ROOM.

Error is:
(line 3, GlobalScript, first if statement in CheckLoop) Type mismatch: cannot convert 'string' to 'int'

OLD_ROOM is a normal room
NEW_ROOM is a 'detail' or 'feature' room - it doesn't have Characters and Objects, rather it is a close-up of an object in a room; a puzzle in this "room" is solved, then we go back to our normal story-driven, visible character room and get on with things.

NicolaGs

Hi,
I am not in front of my computer, so I cannot check right now but at first glance, I'd say that in :
Code: ags
cJulius.ChangeRoom(OLD_ROOM, savex, savey, savedirection);

savedirection should not be a string. It's a particular type of variable...
My first game : I Want Out!

bx83

Solved - it's a number. You just check the loop; don't bother converting. If you use the "eDirection" variables, these aren't strings - they are a "string" *representation* of a list numbers.
:)

Khris

enums are essentially integer constants. When you declare you own, they get int values starting at 1 (iirc). However you can also set your own values.

And you can use the enum name for your variable declaration (instead of int):
Code: ags
  CursorMode previous = mouse.Mode;
  mouse.Mode = eModePointer;
  // ...
  mouse.Mode = previous;

SMF spam blocked by CleanTalk