Author Topic: [SOLVED] Cannot convert string to int - but I'm not ?  (Read 205 times)

bx83

  • Get 'Er Doooooone
I'm sure I'm missing something really, really obvious. Here's the code:

in GlobalScript:
Code: Adventure Game Studio
  1. function CheckLoop (this Character*)
  2. {
  3.         if (this.Loop==0) { return "eDirectionDown"; }
  4.         if (this.Loop==1) { return "eDirectionLeft"; }
  5.         if (this.Loop==2) { return "eDirectionRight"; }
  6.         if (this.Loop==3) { return "eDirectionUp"; }
  7.         if (this.Loop==6) { return "eDirectionDownLeft"; }
  8.         if (this.Loop==7) { return "eDirectionUpLeft"; }
  9.         if (this.Loop==4) { return "eDirectionDownRight"; }
  10.         if (this.Loop==5) { return "eDirectionUpRight"; }
  11. }
  12.  

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: Adventure Game Studio
  1.     savex=cJulius.x;                           //save character's current X position  
  2.     savey=cJulius.y;                           //save character's current Y position
  3.     savedirection=cJulius.CheckLoop();         //get direction of character as String, and save it also
  4.     cJulius.ChangeRoom(NEW_ROOM, 2000, 2000);  //change to new room
  5.  

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: Adventure Game Studio
  1. cJulius.ChangeRoom(OLD_ROOM, savex, savey, savedirection);
  2.  

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.
« Last Edit: 02 Feb 2018, 09:32 by bx83 »

NicolaGs

  • Going nowhere fast
    • NicolaGs worked on a game that was nominated for an AGS Award!
      NicolaGs worked on a game that won an AGS Award!
Re: cannot convert string to int - but I'm not ?
« Reply #1 on: 02 Feb 2018, 07:58 »
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: Adventure Game Studio
  1. 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

  • Get 'Er Doooooone
Re: cannot convert string to int - but I'm not ?
« Reply #2 on: 02 Feb 2018, 09:31 »
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

    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: [SOLVED] Cannot convert string to int - but I'm not ?
« Reply #3 on: 02 Feb 2018, 10:02 »
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: Adventure Game Studio
  1.   CursorMode previous = mouse.Mode;
  2.   mouse.Mode = eModePointer;
  3.   // ...
  4.   mouse.Mode = previous;