Jump to content


Photo

Does GML support something like C++ struct?


  • Please log in to reply
17 replies to this topic

#1 hexdump

hexdump

    GMC Member

  • GMC Member
  • 360 posts
  • Version:GM:Studio

Posted 03 May 2012 - 01:04 PM

Hi,

I have been reading through GML documentation and it seems that it doesn't support any kind of OOP. I would like to know at least if it supports something like C/C++ struct to group data, put into arrays, etc... If not, how do you solve this?

Thanks in advance.
  • 0

#2 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1558 posts
  • Version:GM:Studio

Posted 03 May 2012 - 01:15 PM

you need to read syntax and semantics. game maker is similar but different in different ways.

game maker does have arrays and other ways of storing and accessing and manipulating data through functions start ds_

arrays are not made or accessed this way(ds_ i mean), read the help files for arrays.
  • 0

#3 hexdump

hexdump

    GMC Member

  • GMC Member
  • 360 posts
  • Version:GM:Studio

Posted 03 May 2012 - 01:18 PM

you need to read syntax and semantics. game maker is similar but different in different ways.

game maker does have arrays and other ways of storing and accessing and manipulating data through functions start ds_

arrays are not made or accessed this way(ds_ i mean), read the help files for arrays.


Thanks mate, gonna do it right now.
  • 0

#4 hexdump

hexdump

    GMC Member

  • GMC Member
  • 360 posts
  • Version:GM:Studio

Posted 03 May 2012 - 01:50 PM

Hi again,

Well I have checked this ds_ functions but I think I did not express correctly. It is clear I have to learn a bit more about data structures in gamemaker, but I want to know if there's any type of field grouping like structs/class in C/C++. I supposed it does not exist because I haven't seen anything in the docs. If this is the case how do you people ussually overcome this. For me something like a struct is something all languages should have :).

Thanks in advance.

Edited by hexdump, 03 May 2012 - 01:51 PM.

  • 0

#5 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1558 posts
  • Version:GM:Studio

Posted 03 May 2012 - 02:06 PM

yes there is no class and structs explicitly

as game maker does this for you. objects are effectively an instance of a class and have some unique local variables created for you like x,y,speed..... variables are not private in game maker and can usually be accessed if not changed by using object.variable or with(object){//code here}

game maker objects do have a parenting system that you can use, and you can use event_inherited(); to run code from the parent as well as code specific to the child.

so in a way game maker has pre built classes and structs but they are specific to each resource in game maker like rooms effectively are a class i guess and as such have variables and places to run code...


i never was any good at classes and structs in c++ so sorry if i get the lingo mixed
  • 0

#6 hexdump

hexdump

    GMC Member

  • GMC Member
  • 360 posts
  • Version:GM:Studio

Posted 03 May 2012 - 02:39 PM

yes there is no class and structs explicitly

as game maker does this for you. objects are effectively an instance of a class and have some unique local variables created for you like x,y,speed..... variables are not private in game maker and can usually be accessed if not changed by using object.variable or with(object){//code here}

game maker objects do have a parenting system that you can use, and you can use event_inherited(); to run code from the parent as well as code specific to the child.

so in a way game maker has pre built classes and structs but they are specific to each resource in game maker like rooms effectively are a class i guess and as such have variables and places to run code...


i never was any good at classes and structs in c++ so sorry if i get the lingo mixed


I see. Well, so, as I see in other post perhaps the solution could be to use the Object type and add the properties/atrributes needed. It is a bit dirty because as you said Object is a GM type and comes with things you may not want but I hope it is not too heavy. Here the thread:

http://gmc.yoyogames...dpost&p=3853533

I hope there's a way to create objs from code without forcing me to have the Object defined under Objects in the editor. Is it possible?.

Thanks in advance.

Edited by hexdump, 03 May 2012 - 02:42 PM.

  • 0

#7 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1558 posts
  • Version:GM:Studio

Posted 03 May 2012 - 03:07 PM

yes there is a way to creat objects from code but it is no longer supported post game maker 8.1

obj=object_add();

and other object_ functions can add code and events...


i think your a bit too used to c++. in game maker the WHOLE game is made of objects that have code and sprites associated with them which then are instanced and chucked into a room(a level), rooms have properties as do objects, but these properties are good and are for help for the user, game maker was created as a learning aid.

so your tryint to find way "round" it. but all you have to do is work with objects, its what it is and thats it.

script files can be used as reusable code and functions.

most game maker users creat 1 or more objects that they name controller or something, that just runs the overall code that isnt specific to a player other other objects in the room. they make this object invisible and use it to create instances and run all sorts of code. like you would in a "main" in c++ if my memory serves me correctly. also you can place code in the creation event of a room that runs at the start of that level.
  • 0

#8 GStick

GStick

    All Secrets Exposed

  • GMC Member
  • 1915 posts
  • Version:GM:Studio

Posted 03 May 2012 - 03:19 PM

Do you want to create a "class" at run time, or an instance?

instance_create() is going to be the GM equivalent of:
// c++
Class classInstance;

// gm
instance_create(x, y, Class);

Structs... no. You can fake it though by making an object that you only use for variables. :sweat: GM objects don't have methods anyway... :whistle:
  • 0

#9 Cpt Chuckles

Cpt Chuckles

    GMC Member

  • GMC Member
  • 337 posts
  • Version:GM8.1

Posted 03 May 2012 - 06:15 PM

yeah basically all well-developed projects have at least 1 "control" object that just has no sprite and does stuff in the background. so stuff like that does have to be handled as "object" resources in GM. for whatever "struct" thing you need, you will probably be best off just making a new object, leaving it with no sprite, and plopping it into the room.
  • 0

#10 hexdump

hexdump

    GMC Member

  • GMC Member
  • 360 posts
  • Version:GM:Studio

Posted 03 May 2012 - 06:29 PM

Do you want to create a "class" at run time, or an instance?

instance_create() is going to be the GM equivalent of:

// c++
Class classInstance;

// gm
instance_create(x, y, Class);

Structs... no. You can fake it though by making an object that you only use for variables. :sweat: GM objects don't have methods anyway... :whistle:


If I said class I meant to say instance, sorry.

What you expose with the instance_create is what I was thinking of.

And my previous question was about if the object I want to instantiate must be a object that I created on the editor or is an "Empty object" I can instantiate.

Thanks.
  • 0

#11 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1558 posts
  • Version:GM:Studio

Posted 03 May 2012 - 06:35 PM

as i said object_add(); creates an empty object that you can code each of the events, and then use it with instance_create to make an instance of the new object to apear. but this is at run time. it is a little useful but is only possible on GM8.1 and before(i dont know how far back). as with game maker studio they have removed support for dynamic object coding and dynamic variables among others
  • 0

#12 hexdump

hexdump

    GMC Member

  • GMC Member
  • 360 posts
  • Version:GM:Studio

Posted 04 May 2012 - 01:31 PM

as i said object_add(); creates an empty object that you can code each of the events, and then use it with instance_create to make an instance of the new object to apear. but this is at run time. it is a little useful but is only possible on GM8.1 and before(i dont know how far back). as with game maker studio they have removed support for dynamic object coding and dynamic variables among others


Oh, thanks for the clarification.

It doesn't sound good. Why remove the dynamic object thing? :/.

HexDump.
  • 0

#13 Jack Indie Box

Jack Indie Box

    GMC Member

  • GMC Member
  • 1558 posts
  • Version:GM:Studio

Posted 04 May 2012 - 01:42 PM

well they now have multiple compilers with gm studio, and they want to make them coherent. and atleast 1 of them does not support un compiled code i think was the explanation. basically screwed up my already broken game imported(and "fixed) in game maker studio to the point i think im gonna have to scrap it.
  • 0

#14 hexdump

hexdump

    GMC Member

  • GMC Member
  • 360 posts
  • Version:GM:Studio

Posted 04 May 2012 - 09:23 PM

well they now have multiple compilers with gm studio, and they want to make them coherent. and atleast 1 of them does not support un compiled code i think was the explanation. basically screwed up my already broken game imported(and "fixed) in game maker studio to the point i think im gonna have to scrap it.

So they killed my only chance of having a way to group data (aka struct, etc...). How am I supposed then to simulate such thing now :/. I understand GML could not be a OOP language but the grouping thing is such a basic/sensible/useful thing that I'm really amazed they remove the only way to simulate it, or are there any other ways? Suggestions are welcomed.

I know I can sound really egoist here, but GM should just focus on GMS right now. They should create a really great product, put all resouces on it and then if they want to release some cut down versions it is ok, but mantaining all this battery of programs/versions seems a bit counterproductive IMO.

Edited by hexdump, 04 May 2012 - 09:29 PM.

  • 0

#15 rwkay

rwkay

    YoYo Games CTO

  • YoYo Games Staff
  • 2357 posts
  • Version:Unknown

Posted 04 May 2012 - 09:31 PM

While there are no structures you can use a ds_map as a dictionary object for storing keys and values.

The lack of structs and lots of other language features will be remedied in GMNext.

Russell
  • 0

#16 dannyjenn

dannyjenn

    GMC Member

  • GMC Member
  • 2736 posts
  • Version:Mac

Posted 04 May 2012 - 09:36 PM

It's the way GM is set up... it's object-oriented, but all objects are made in the software's interface itself, not with code. There's really no need to use code to create objects in the first place, unless you're just trying to make a quick object without going through the interface.

As for structs... I don't really remember what they're even used for (as I never even needed to use them). Aren't they pretty much just a lessened version of a class? Classes are basically the same thing as objects, so I'm guessing you can just use objects for structs as well.
  • 0

#17 C_Pike

C_Pike

    GMC Member

  • GMC Member
  • 618 posts
  • Version:GM8.1

Posted 04 May 2012 - 10:06 PM

So they killed my only chance of having a way to group data (aka struct, etc...). How am I supposed then to simulate such thing now :/. I understand GML could not be a OOP language but the grouping thing is such a basic/sensible/useful thing that I'm really amazed they remove the only way to simulate it, or are there any other ways? Suggestions are welcomed.

I know I can sound really egoist here, but GM should just focus on GMS right now. They should create a really great product, put all resouces on it and then if they want to release some cut down versions it is ok, but mantaining all this battery of programs/versions seems a bit counterproductive IMO.


GM is made for:
1) me, whom for whatever reason, cannot grasp higher concepts, and is pandered to with GML.
2) The flexible... Bend or Break, Adapt or Die... :thumbsup:

Edited by C_Pike, 04 May 2012 - 10:06 PM.

  • 0

#18 hexdump

hexdump

    GMC Member

  • GMC Member
  • 360 posts
  • Version:GM:Studio

Posted 04 May 2012 - 10:48 PM



So they killed my only chance of having a way to group data (aka struct, etc...). How am I supposed then to simulate such thing now :/. I understand GML could not be a OOP language but the grouping thing is such a basic/sensible/useful thing that I'm really amazed they remove the only way to simulate it, or are there any other ways? Suggestions are welcomed.

I know I can sound really egoist here, but GM should just focus on GMS right now. They should create a really great product, put all resouces on it and then if they want to release some cut down versions it is ok, but mantaining all this battery of programs/versions seems a bit counterproductive IMO.


GM is made for:
1) me, whom for whatever reason, cannot grasp higher concepts, and is pandered to with GML.
2) The flexible... Bend or Break, Adapt or Die... :thumbsup:


Well, I will start writing the port of my game and see what people come with for some problems I have in my head. Perhpas I need to get my hands dirty :).
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users