Thank you, Mr. Dailly, for this subforum and its posts. (I only wish I knew of this sooner. I've been away for awhile. I wouldn't mind adding some different input to a couple of the other threads.)
I want to say I like the idea of adding structures (my first real look at them), and of allowing constants to be defined in code, but as ..I'll say a novice-to-intermediate programmer, I have some concerns. I have a nice ability to ramble, thus I'll
try to keep it pointed in this post. $:^ ]
I
like defining constants the way GM8 defines them -- but perhaps only because I don't know the alternative. GM6- didn't have this, but with GM7+, I can now softcode a
lot yet have
color-coded highlights to super-quickly visually distinguish between mere variables and a constant. (I usually go for the all-caps naming scheme, but on some stuff, it's just annoying -- for one example, using custom color constants is more awkward with c_blue c_orange C_LEO_BLUE C_MIKEY_ORANGE c_black etc. and less awkward with c_blue c_orange_ c_leo_blue c_mikey_orange c_black etc.)
I hear about intellisense, but I'm curious how well it might work to, say, 1. write a script that does plenty of nifty stuff, including defining certain constants for any given instance that calls the script, then 2. call this script from an object's Create Event and 3. refer to these object- (or even instance- ) specific constants in another event (such as End Step or Draw Event). Is it seriously easy enough to implement a GML-created constant with color coding elsewhere? I think it was Smarty in another thread who mentioned a concept similar to this, which I'll illustrate with a simplified example:
// object's Create Event
const c_favorite = choose(c_blue,c_red,c_orange,c_purple);
// object's Mouse Event for Left Pressed
if (image_blend == c_white) {
image_blend = c_favorite;
} else {
image_blend = c_white;
}
My basic question is, using this example, would/could this actually color-code the text "c_favorite" in some GML embedded into the Mouse Event? And if this code is instead in a script, and the script gets called from the event, would/could it still receive that nice color-coding? (It doesn't seem very
easy to me, but I'm nowhere nearly as advanced as people like Smarty--however, to my ears, my concern sounds the same as Smarty's.)
"Real world" application: My memory may be foggier than I thought, but in my "9 to 5," when I define a constant in PHP, it doesn't get color-coded in other PHP files, even though these other scripts and subscripts obviously
use said constants.
--
why even have structures? game maker has object oriented programming. just use instances of objects to store data. they are perfect for storing data in variables, and storing build in functions in events.
The disadvantages have already been lain out. I'll let them stand for me.
const CLUBS = 0;
const HEARTS = 1;
const SPADES= 2;
const DIAMONDS = 3;
struct UndoSlot
{
Rank,
Suit,
Stack,
Active
};
MyArray[0] = struct_create( UndoSlot );
MyArray[0].Rank = 1;
MyArray[0].Suit = CLUBS;
MyArray[0].Stack = 3;
MyArray[0].Active = true;structures. objects. same [PKB snip] thing.
look, it's even less typing.
clubs=0
hearts=1
spades=2
diamonds=3
MyArray[0]=instance_create(0,0,undoSlot)
MyArray[0].rank=1
MyArray[0].suit=clubs
MyArray[0].stack=3
MyArray[0].active=1
Oh my. I believe your example just sold me on structures more than anyone else's. My mind said, "You mean, I can
define a few lines of text for a structure
instead of
designing an entire object (with all its built-in overhead of variables, events, etc.) and strategically placing one or more instances of it into whichever appropriate rooms, taking care to account for order-of-instance-creation to prevent uninitialized errors,
and use the same easy code?"
Yes. I believe I'll take
// initialize somewhere
struct undo_slot {
rank,
suit,
stack,
active
};
card_slot[0] = struct_create(undo_slot);
card_slot[0].rank = 1;
card_slot[0].suit = CLUBS;
card_slot[0].stack = 3;
card_slot[0].active = true;
over
// SET UP AN ENTIRE o_ctrl_card_slot OBJECT
solid = false;
visible = false;
// ETC.
// ETC.
// YET ANOTHER OBJECT IN MY TREE IN THE o_ctrl FOLDER, IF NOT WITH MORE SUBFOLDER-ING
/* FEEL TERRIBLE KNOWING I'M WASTING *SO* MANY VARIABLES AND EVENTS AND SO FORTH
ON SOMETHING THAT'S REALLY NOT MUCH MORE THAN A FANCIFIED ARRAY */
card_slot[0] = instance_create(0,0,undo_slot);
card_slot[0].rank = 1;
card_slot[0].suit = CLUBS;
card_slot[0].stack = 3;
card_slot[0].active = true;
any day.
And on another quickie note, Mr. slayer, it wasn't eternally condemned. There's no need to curse it. $:^ J
--
On Dannyboy's "Silent scope-related errors" issue and LSnK's response: ~nodnod~ I could see this remedied a lot even if only the temporary var scope got a different highlight (from the point it's defined, downward). That'd be convenient and nifty.
--
An additional note to Mike, syntax and scope:
struct card_type {
suit,
face
}
...looks more-or-less fine, but what happens when scope gets involved?
var stuff, things;
var struct card_type {
suit,
face
}
For consistency with defining other variables' scopes using var or globalvar, what are the advantages and disadvantages to these kinds of syntaxes?
var stuff, card_type, things;
struct card_type {
suit,
face
}
// VS.
var stuff, struct card_type, things;
struct card_type {
suit,
face
}
// VS.
var stuff, struct card_type {suit,face}, things;
The last seems pretty logical, especially if defining more than one structure...
struct card_type {suit,face}, vehicle_stat {make,model,year,manual,paint,etc};
// SAME CODE, DIFFERENTLY WRITTEN
struct card_type {
suit,
face
}, vehicle_stat {
make,
model,
year,
manual,
paint,
etc
}
...which would then lead to the question of scope definitions...
var card_type, vehicle_stat;
struct card_type {}, vehicle_stat {};
// OR
var card_type, vehicle_stat;
struct card_type {
// ...
}
struct vehicle_stat {
// ...
}
// OR
var struct card_type {
// ...
}, vehicle_stat {
// ...
}
// OR
var struct card_type {
// ...
}
var struct vehicle_stat {
// ...
}
...which then leads me to wonder about making it look more GML-syntaxy. For example,
var card_type, vehicle_stat;
card_type = struct_create(suit,face);
vehicle_stat = struct_create(make,model,year,manual,paint,etc);
...or (come to think of it) would using a function limit it to only 16 arguments? (Hmmmmmmmmmm... Perhaps include a couple struct_* functions which only go up to 16 args, whereas the "standard" struct syntax would allow arbitrary? Kind of like how the Execute Script Action only allows 5 arguments, whereas calling my_script() from any Action (such as Execute Code) gives you up to 16. And, kind of like how users have the option to write argument2+argument7
or argument[2]+argument[7].)
Just some thoughts, really...
--
Regards,
Edited by ParodyKnaveBob, 06 February 2011 - 11:26 PM.