Struct?

Non-platform specific questions.

Struct?

Postby Hblade » Fri Apr 27, 2012 2:40 pm

What is a struct, and how can I use it?
thanks
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4366
Joined: Fri Dec 08, 2006 11:14 pm
Score: 169 Give a positive score

Re: Struct?

Postby SuperSonic » Fri Apr 27, 2012 3:04 pm

A struct is similar to a class. But I'm not sure what it's really used for :)
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1444
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Struct?

Postby Hblade » Fri Apr 27, 2012 3:12 pm

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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4366
Joined: Fri Dec 08, 2006 11:14 pm
Score: 169 Give a positive score

Re: Struct?

Postby skydereign » Fri Apr 27, 2012 3:58 pm

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.
User avatar
skydereign
 
Posts: 3453
Joined: Mon Jul 28, 2008 8:29 am
Score: 570 Give a positive score

Re: Struct?

Postby SuperSonic » Fri Apr 27, 2012 4:02 pm

But what about a class? Isn't that basically the same thing? :)
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1444
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Struct?

Postby skydereign » Fri Apr 27, 2012 4:10 pm

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.
User avatar
skydereign
 
Posts: 3453
Joined: Mon Jul 28, 2008 8:29 am
Score: 570 Give a positive score

Re: Struct?

Postby SuperSonic » Fri Apr 27, 2012 4:45 pm

That's cool! I didn't know that :D
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1444
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Struct?

Postby Hblade » Fri Apr 27, 2012 7:21 pm

Hey thanks sky!
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4366
Joined: Fri Dec 08, 2006 11:14 pm
Score: 169 Give a positive score

Re: Struct?

Postby Game A Gogo » Sat Apr 28, 2012 1:01 pm

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
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3464
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Struct?

Postby Hblade » Sat Apr 28, 2012 7:34 pm

struct for some reason crashes Game Editor when I click "Add" in global code
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4366
Joined: Fri Dec 08, 2006 11:14 pm
Score: 169 Give a positive score

Re: Struct?

Postby skydereign » Sat Apr 28, 2012 8:12 pm

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;
};
User avatar
skydereign
 
Posts: 3453
Joined: Mon Jul 28, 2008 8:29 am
Score: 570 Give a positive score

Re: Struct?

Postby Hblade » Sat Apr 28, 2012 9:57 pm

oh thats why, thanks sky :) I was doing it like this:
Code: Select all
struct something() {
ints
}
xD
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4366
Joined: Fri Dec 08, 2006 11:14 pm
Score: 169 Give a positive score

Re: Struct?

Postby SuperSonic » Sun Apr 29, 2012 3:22 am

You missed the semi-colon at the end :)
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1444
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Struct?

Postby GEuser » Wed Oct 24, 2012 9:13 pm

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.
GEuser
 
Posts: 204
Joined: Thu Jan 05, 2012 3:08 pm
Score: 18 Give a positive score

Re: Struct?

Postby skydereign » Wed Oct 24, 2012 9:43 pm

That is because you are fusing a function declaration with a struct declaration (notice the parenthesis).
Code: Select all
struct person
{
    int age;
};
User avatar
skydereign
 
Posts: 3453
Joined: Mon Jul 28, 2008 8:29 am
Score: 570 Give a positive score

Next

Return to General

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest