How do you use "struct" on linux

Linux specific questions and discussion

How do you use "struct" on linux

Postby GEuser » Thu Oct 25, 2012 1:32 pm

Do any Linux users know what you need to do to use a struct in GE?

keep getting these errors:

Error line 3: Expected ;
Error line 4: Expected ;

Code used:-
Code: Select all
struct person
{
    int Age = 0;
};


I've tried all sorts of struct delcarations but it could just as easily be an issue with the linux version of GE. Any ideas?
GEuser
 
Posts: 204
Joined: Thu Jan 05, 2012 3:08 pm
Score: 19 Give a positive score

Re: How do you use "struct" on linux

Postby MrJolteon » Thu Oct 25, 2012 4:06 pm

Try removing the semicolon from line 4.
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

Re: How do you use "struct" on linux

Postby GEuser » Thu Oct 25, 2012 4:23 pm

I've tried all the different permutations from online research so I know it's not typo issues, its to do with the actual gE version of linux or something else.

Maybe, I need additional libraries to use struct. Libraries specific for C as opposed to C++, header files or something of that sort. Not too knowledgeable on this front but thought struct was part of standard C library anyway so it should be included (not sure about this)?

Thanks for your reply.
GEuser
 
Posts: 204
Joined: Thu Jan 05, 2012 3:08 pm
Score: 19 Give a positive score

Re: How do you use "struct" on linux

Postby skydereign » Thu Oct 25, 2012 8:14 pm

That is because you can't set default values for structs. Remove the = 0; when declaring the age variable and it will work.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How do you use "struct" on linux

Postby GEuser » Fri Oct 26, 2012 1:04 am

WOW!!! it actually excepted it this time round.

I did as you instructed, this:
Code: Select all
struct person
{
     Age;
};


then I added it in Gobal Code Editor as person. The thing is how do I assign it a value to Age. How do I actually access it in the code.? Was I right to add it as person in Gobal Code Editor? Sorry to throw up so many questions but these structs would really be useful for some of the stuff I hope to do.

Really appreciate it Sky, thanks again :D
GEuser
 
Posts: 204
Joined: Thu Jan 05, 2012 3:08 pm
Score: 19 Give a positive score

Re: How do you use "struct" on linux

Postby skydereign » Fri Oct 26, 2012 1:11 am

I assume you mean this by your code (otherwise you aren't creating an integer variable).
Code: Select all
struct person
{
    int Age;
}


You can think of a struct as a variable type (int, char, etc). You need to declare an actual variable using the struct you just defined. If you only want one global version of the struct, you can just add this to the bottom.
Code: Select all
struct person var_name;

That declares a person struct variable. To access the structs contents, you just use var_name.variable, in your case var_name.Age.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How do you use "struct" on linux

Postby GEuser » Fri Nov 02, 2012 11:12 pm

Thanks!

think I'll leave these for another time.
GEuser
 
Posts: 204
Joined: Thu Jan 05, 2012 3:08 pm
Score: 19 Give a positive score


Return to Linux

Who is online

Users browsing this forum: No registered users and 1 guest

cron