Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Captain Mostly on Thu 04/03/2004 00:43:29

Title: bloomin' strings!
Post by: Captain Mostly on Thu 04/03/2004 00:43:29
I've got two strings in variables (saddly they have to be in variables) and I want to swap them round.

I've been trying to use strCopy, but that doesn't seem to like having both strings represented with variables
i.e. it wants:
strCopy(juju,"pupu");
not
strCopy(juju,pupu);

Can anyone suggest ways to juggle strings in variables?

Thankyou!

P.S. I "RTFM"'d already, but couldn't see anything!
Title: Re:bloomin' strings!
Post by: Gilbert on Thu 04/03/2004 01:41:42
Strange, StrCopy(juju,pupu) should work.

Are you sure that the 2 variables are declared as type string ?
Title: Re:bloomin' strings!
Post by: a-v-o on Thu 04/03/2004 10:41:30
What error message do you get when you try "strCopy(juju,pupu);"?
Is it a compiler error message or a runtime error?
Title: Re:bloomin' strings!
Post by: Gilbert on Thu 04/03/2004 10:45:22
Yep moreover it's StrCopy not strCopy.
Title: Re:bloomin' strings!
Post by: Captain Mostly on Thu 04/03/2004 12:17:26
If memory serves, it recognises the command, but sais type mis-match. I'm SURE that I declared them both as strings!

One of them is in an array i.e.

StrCopy(juju,pupu[1]);

should that make a difference?
Title: Re:bloomin' strings!
Post by: SSH on Thu 04/03/2004 12:27:22
AFAIK, you can't have arrays of strings in AGS... so may be that's the problem!

btw, strcpy and StrCopy both do the same thing
Title: Re:bloomin' strings!
Post by: Captain Mostly on Thu 04/03/2004 14:34:24
you can't have an array of strings?!?!?! blahh!

What's AFAIK?
Title: Re:bloomin' strings!
Post by: Ishmael on Thu 04/03/2004 15:09:41
Isn't the character[CHARID].name for example an array of strings?

AFAIK = As Far As I Know
Title: Re:bloomin' strings!
Post by: SSH on Thu 04/03/2004 15:14:56
EDIT: OOPS got it wrong first time

I think you can have arrays of structs and strings inside the structs, but you can't have arrays of strings directly.

So Captain, your solution is:

#define MAX_STRING_LEN 40
struct MostlyStringArray {
 char s[MAX_STRING_LEN];
}; // This goes in script header

MostlyStringArray pupu[10];

instead of
string pupu[10];

and then instead of referncing pupu[1], you need to say pupu[1].s, also there is the limit (40 above, but set to whatever you like) on the size... the dynamic string allocation stuff doesn't work in arrays.

Alternatively, if you only have one array of strings you could use Set/GetGlobalString

Title: Re:bloomin' strings!
Post by: Captain Mostly on Thu 04/03/2004 16:04:36
are strcuts in the readme, as I'm going to need to understand them better before I can use them...

When you say the script header, you presumably mean along side all the "import function..." gubbins?

Ans what's the "s" for in "char s[MAX_STRING_LENGTH]" ?

Tell me if any of this is an RTFM jobby!
Title: Re:bloomin' strings!
Post by: SSH on Thu 04/03/2004 16:20:22
They are not an RTFM becuase they're an undocumented feature. However, AGS uses them a lot internally, so I doubt they're going to disappear any time soon.

Structs are basically a collection of objects into a lump. You have already used them, as anywhere there is a "." in AGS is where there is a struct. For example, this is an implicit declaration in AGS:

struct MouseState {
 int  x,y;
 };
MouseState mouse;

Which means that when you say "mouse.x" or "mouse.y" in your scripts, it look at variable mouse and sees it is of type "MouseState" (just like variable x might be an "int". It then looks up MouseState type and sees that it is a struct with two integer components called x and y. It then retrieves the appropriate component of the struct.

the character variable is an array of structs, so that's how you access character[EGO].room, etc. The only way of having 2d arrays in AGS just now is to use a struct wrapper around it. Arrays of strings are effectively 2D arrays of chars, so they can only be implemented like this.

If you get a C textbook or web tutorial and look up structs and strings there, it can probably explain it better than me...

To answer your specific questions: yes, beside the import jobbies and The s is the string (or array of char) component of the struct



Title: Re:bloomin' strings!
Post by: Captain Mostly on Fri 05/03/2004 09:48:24
ahh! Thankyou! It works!!! HURRAH! AND I understand how it works!!! EVEN BETTER!

You have been jolly jolly helpful!  :-*
Title: Re:bloomin' strings!
Post by: Scorpiorus on Fri 05/03/2004 22:13:09
The only thing I'd like to add is define MAX_STRING_LEN as 200 because AGS assumes that all its strings allocate that amount of memory. Otherwise there is a possibility the other data can get corrupted.

~Cheers
Title: Re:bloomin' strings!
Post by: Captain Mostly on Mon 08/03/2004 09:28:56
Ahhh! I was just about to ask why 'tis that when I say "StrCopy(pupu[3].s,"Tra la la") the contents of pupu[3+].s (i.e. everything after 3) is blanked! I'll re-set my MAX_STRING_LEN as soon as I get home! Hurrah!