Page 1 of 2

Struct?

PostPosted: Fri Apr 27, 2012 2:40 pm
by Hblade
What is a struct, and how can I use it?
thanks

Re: Struct?

PostPosted: Fri Apr 27, 2012 3:04 pm
by SuperSonic
A struct is similar to a class. But I'm not sure what it's really used for :)

Re: Struct?

PostPosted: Fri Apr 27, 2012 3:12 pm
by Hblade
From what I seen, it bunches together ints or other variables I think, so like this:
Code: Select all
struct pickles(){
    int var
    int var2
    int var3
    int var4
}


but whtas the purpose? xD

Re: Struct?

PostPosted: Fri Apr 27, 2012 3:58 pm
by skydereign
You know how actor's have a bunch of variables? An Actor is a struct, and it is very useful for all of those variables to be bunched into one coherent structure. If you have several variables that all work together, it makes sense to want to put them into a single place, structures allow you to do this. They also provide a way of making complex data types that aren't really possible (cleanly at least) without them.

Re: Struct?

PostPosted: Fri Apr 27, 2012 4:02 pm
by SuperSonic
But what about a class? Isn't that basically the same thing? :)

Re: Struct?

PostPosted: Fri Apr 27, 2012 4:10 pm
by skydereign
Classes aren't in c, so saying its similar to a class doesn't help anyone who doesn't know what either is. In c++ classes and structs are very similar, but classes have a different default permissions (public versus private data). In c++ you can also create member functions which helps create a more object oriented approach, which is notably absent in c.

Re: Struct?

PostPosted: Fri Apr 27, 2012 4:45 pm
by SuperSonic
That's cool! I didn't know that :D

Re: Struct?

PostPosted: Fri Apr 27, 2012 7:21 pm
by Hblade
Hey thanks sky!

Re: Struct?

PostPosted: Sat Apr 28, 2012 1:01 pm
by Game A Gogo
skydereign wrote:Classes aren't in c, so saying its similar to a class doesn't help anyone who doesn't know what either is. In c++ classes and structs are very similar, but classes have a different default permissions (public versus private data). In c++ you can also create member functions which helps create a more object oriented approach, which is notably absent in c.


One of the reasons I don't use GE much anymore ): I got addicted to classes in college xD

Re: Struct?

PostPosted: Sat Apr 28, 2012 7:34 pm
by Hblade
struct for some reason crashes Game Editor when I click "Add" in global code

Re: Struct?

PostPosted: Sat Apr 28, 2012 8:12 pm
by skydereign
The following should work. One thing though is you need to add the semi at the end.
Code: Select all
struct var_name
{
    int variables;
};

Re: Struct?

PostPosted: Sat Apr 28, 2012 9:57 pm
by Hblade
oh thats why, thanks sky :) I was doing it like this:
Code: Select all
struct something() {
ints
}
xD

Re: Struct?

PostPosted: Sun Apr 29, 2012 3:22 am
by SuperSonic
You missed the semi-colon at the end :)

Re: Struct?

PostPosted: Wed Oct 24, 2012 9:13 pm
by GEuser
I can't get the struct declaration to work.

Code: Select all
struct person ()
{
        int age=0;
};



The above entry in global editor crashed. Question is what would I add it as in the add field (person)? Is their problems with the linux version of GE? Hope, this can be resolved it eould be really useful in some stuff I'm planning.

Re: Struct?

PostPosted: Wed Oct 24, 2012 9:43 pm
by skydereign
That is because you are fusing a function declaration with a struct declaration (notice the parenthesis).
Code: Select all
struct person
{
    int age;
};