SUGGESTIONS: Structs -- And Arrays.

Started by monkey0506, Fri 01/07/2005 04:11:29

Previous topic - Next topic

monkey0506

I have some suggestions for structs, which I personally could make great use of, and was just wondering about implementation:

struct within struct support -- Use of custom struct types inside of other structs.

static variable support -- Custom static variables.  We can have static functions, why not variables?
(Edit by strazer: http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=543)

string within struct support -- This would be nice.
(Edit by strazer: http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=528)

Well, I guess that's about it.  If not official support, it would be nice to have implemented support (i.e., it works, it's just not "supported") of these features.

Edit:  Ooh... And what about an array of strings?  I could definitely make use of that...
(Edit by strazer: http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=111)

Edit:  How about accessing protected members of an object of a struct from a static function of said struct.  For example:

struct MyVar {
  protected import static void SetVal(int value);
  protected int Val;
  import static void Initialize();
  };

MyVar variable;

static void MyVar::Initialize() {
  variable.SetVal(5);
  }

Or something like that.  It's a crappy example, but it kind of displays what I want to do.

Kweepa

You just wanted to type "protected import static void" :)
You forgot const though.

You can add char[200] to a struct instead of a string, I believe.

I guess the problem with static variables in structs is that they'd require initialization when the script loaded. You could always have a global variable external to the struct that was accessed through static functions inside the struct. For example, instead of

struct Jimmy
{
  static int Bob;
};
int Jimmy::Bob = 0;

you'd write

struct Jimmy
{
  static void SetBob(int bob) { gJimmyBob = bob; }
  static int GetBob() { return gJimmyBob; }
};
int gJimmyBob = 0;
Still waiting for Purity of the Surf II

monkey0506

1.  Heh.  No, but it was fun realizing that's what I needed the first time I wrote it.

B.  Yes, you can, but it gets cumbersome working with those.  I guess the real reason I wanted this was for string arrays (which aren't supported.)

III.  I'm using a global variable, but it's messy having to place a variable that has ONLY to do with one specific struct (which is global) outside the struct; whereas it would be easier to keep it within the struct.  It helps remove amibiguity as to what it is, why it's global, etc.

~.  You've managed to provide workarounds (that I knew of) for two of my problems.  Out of five.  I commend you.


Just kidding.  Thanks for trying. :D

Pumaman

I agree that all your suggestions would be useful, and I think we've discussed them before in the context of the new scripting language. I can't promise when they might be implemented, though.

SSH

Quote from: monkey_05_06 on Sat 02/07/2005 01:10:11
B.  Yes, you can, but it gets cumbersome working with those.  I guess the real reason I wanted this was for string arrays (which aren't supported.)

Put a char[200] in a struct and have an arrayof those structs, voila... string arrays
12

monkey0506

An array of strings INSIDE a struct*?  Interesting info Chris.  Too bad you can't just release it now.  Which is kind of the only way I could possibly continue to program in AGS because I just feel dirty creating 3 SMs so that I can put structs inside of each other... :-\  And the alternative scares me (I made a version in legacy code (which is basically the way I would have to code it), and we all know how that worked out. :-X)


*Yes, I provided some means for this to be possible, via the inner struct type being in a header file prior to the struct containing it, but I'm discussing full implementation here, not workarounds (especially not in this case).

SMF spam blocked by CleanTalk