One of the String arguments supplied was not a string

Started by Cogliostro, Tue 05/11/2013 18:15:18

Previous topic - Next topic

Cogliostro

Okay, going a bit bonkers here.  Created an ENUM, built an array with it, "Displayed" the contents, and it all shows up pretty as a picture.  Then I move the ENUM and ARRAY to Global Script and try to write all of the exact same text into a GUI Label, and I get an error: "One of the String arguments supplied was not a string."  If I eliminate the string it works, so *most* of the code it valid, but how do I get it to display the name?!

Code: ags

//Global Script.ash
struct Place {
  String Name;
  int ID;
  int CurRoom;
  int Order;
  int PosX;
  int PosY;
  int ObjNum;
};
      
Place Details[11]



THIS CODE WORKS!
Code: ags

function ShowOff() {
    Display("Name: %s[ID: %d[PosX: %d[PosY: %d[Room: %d",
      Details[DetailProp].Name,
      Details[DetailProp].ID, 
      Details[DetailProp].PosX, 
      Details[DetailProp].PosY, 
      Details[DetailProp].CurRoom);
}


But this code generates the error?!  What's the difference?!
Code: ags

//Room Script
function room_Load()
{
  lProp.Text=String.Format("Name: %s[ID: %d[PosX: %d[PosY: %d[Room: %d",
      Details[DetailProp].Name,
      Details[DetailProp].ID, 
      Details[DetailProp].PosX, 
      Details[DetailProp].PosY, 
      Details[DetailProp].CurRoom);


Any help would be appreciated,
- Cogliostro


Edit by Andail: fixed code tags.
"First things first, but not necessarily in that order." - Dr. Who

Cogliostro

A solution - sort of...

I narrowed down the cause of the problem.  I ran the ShowOff() function in both rooms.  In the room where I populated the data into the array, DETAILS, it worked.  In the other room, it failed.  Now, when I moved the Array into the GlobalScript.ASH, because I wanted the values I entered in the one room to be available in the next, but apparently that isn't going to happen.  So, for the moment, I moved the ARRAY and ENUM into the headers of both rooms, and entered the data in twice.  Was there supposed to be a way to make the array data accessible from both rooms?

- Cogliostro

P.S.  I'm going to let this kick around for a day or so before flagging it resolved.
"First things first, but not necessarily in that order." - Dr. Who

Khris

The problem is you declared Place Details[11]; in the header, not the main script. Since the header is put on top of all scripts "below" it, that created a separate array for each room.
An int defaults to 0, but a String defaults to null, which isn't a String (a String is actually a pointer to a char[]).

You have to do:
Code: ags
// header

// struct definition here

import Place Details[11];


Code: ags
// main script

Place Details[11];
export Details;

Cogliostro

#3
Hmm... still having trouble...

Global Script
Code: ags

Place Details[11];
export Details[11];



Global Header
Code: ags

struct Place {
  String Name;
  int ID;
  int CurRoom;
  int Order;
  int PosX;
  int PosY;
  int ObjNum;
};

import Details[11];


Getting the error: Failed to save room room1.crm; details below
GlobalScript.ash(19): Error (line 19): expected variable or function after import, not 'Details'


Of course, if I change the IMPORT line to read:
Code: ags
 import Place Details[11];


I get the error: GlobalScript.asc(717): Error (line 717): export parse error at '['

If I updated the line in the global script to include the Struct type: PLACE. 
Then I get: GlobalScript.asc(717): Error (line 717): invalid export symbol 'Place'



I've imported functions before, but doing this with a custom array is driving me nuts!

- Cogliostro
"First things first, but not necessarily in that order." - Dr. Who

Khris

Either copy and paste my code or look at it again very carefully.
I'm confident it will work if you use it exactly as I put it (you haven't done so yet).

Cogliostro

Kris!

when I exported it at the bottom of the global script I included the brackets and size of the array!!  Once I cleared that out, everything worked like a charm.  For the record, you just earned a spot in the credits!

Thanks,
Cogliostro
"First things first, but not necessarily in that order." - Dr. Who

Khris

You're welcome, glad it's working :)

Btw, you can move the export line directly below the declaration line, it doesn't have to be at the bottom of the script.

SMF spam blocked by CleanTalk