bloomin' strings!

Started by Captain Mostly, Thu 04/03/2004 00:43:29

Previous topic - Next topic

Captain Mostly

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!

Gilbert

Strange, StrCopy(juju,pupu) should work.

Are you sure that the 2 variables are declared as type string ?

a-v-o

What error message do you get when you try "strCopy(juju,pupu);"?
Is it a compiler error message or a runtime error?

Gilbert

Yep moreover it's StrCopy not strCopy.

Captain Mostly

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?

SSH

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
12

Captain Mostly

#6
you can't have an array of strings?!?!?! blahh!

What's AFAIK?

Ishmael

Isn't the character[CHARID].name for example an array of strings?

AFAIK = As Far As I Know
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

SSH

#8
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

12

Captain Mostly

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!

SSH

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



12

Captain Mostly

ahh! Thankyou! It works!!! HURRAH! AND I understand how it works!!! EVEN BETTER!

You have been jolly jolly helpful!  :-*

Scorpiorus

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

Captain Mostly

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!

SMF spam blocked by CleanTalk