This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Structures in Pawn?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Afrow UK
Junior Member
Join Date: Feb 2007
Old 06-30-2007 , 06:53   Structures in Pawn?
Reply With Quote #1

Does Pawn allow the creation of structures like C's struct?

e.g.
struct OLDITEM
{
int iChecked;
int iDisableCheck;
BOOL bDisableEdit;
int iOldIndex;
char *szOldText;
};

Currently I have half a dozen global arrays :S

Stu
Afrow UK is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 06-30-2007 , 06:56   Re: Structures in Pawn?
Reply With Quote #2

check this: http://forums.alliedmods.net/showthread.php?t=26634
__________________
Impossible is Nothing
Sylwester is offline
Afrow UK
Junior Member
Join Date: Feb 2007
Old 06-30-2007 , 07:18   Re: Structures in Pawn?
Reply With Quote #3

Cheers
Afrow UK is offline
Afrow UK
Junior Member
Join Date: Feb 2007
Old 06-30-2007 , 07:20   Re: Structures in Pawn?
Reply With Quote #4

On a side note, you can do this:

Code:
enum my_struct
{
  Float:my_float,
  Handle:my_handle,
  bool:my_boolean,
  my_string[32]
};
No type casting necessary then.

One problem here though is that my_float, my_handle, my_boolean and my_string are now defined globally, even though they are contained in an enumerator. Silly as it may seem, you cannot now use new Float:my_float etc in a procedure.

Stu

Last edited by Afrow UK; 06-30-2007 at 07:36.
Afrow UK is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 06-30-2007 , 11:03   Re: Structures in Pawn?
Reply With Quote #5

Please note that these are in essence hacked enums. In my experience I've had way too many problems when trying to deal with them. For example, to properly access your variables with float tags within the enum, you must calculate a float offset to it. Or, at least that's what I've been told.

If in this instance it works for you, more power to ya ;).
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
P34nut
AMX Mod X Beta Tester
Join Date: Feb 2006
Location: Netherlands
Old 06-30-2007 , 11:06   Re: Structures in Pawn?
Reply With Quote #6

I like them, I use them and I have never had any problems with them
__________________
All you need to change the world is one good lie and a river of blood
P34nut is offline
sawce
The null pointer exception error and virtual machine bug
Join Date: Oct 2004
Old 07-01-2007 , 01:13   Re: Structures in Pawn?
Reply With Quote #7

Quote:
Originally Posted by Zenith77 View Post
Please note that these are in essence hacked enums.
Cleaner code.

Quote:
For example, to properly access your variables with float tags within the enum, you must calculate a float offset to it. Or, at least that's what I've been told.
What?
__________________
fyren sucks
sawce is offline
Old 07-01-2007, 11:26
Zenith77
This message has been deleted by Zenith77. Reason: Corrected.
sawce
The null pointer exception error and virtual machine bug
Join Date: Oct 2004
Old 07-01-2007 , 14:01   Re: Structures in Pawn?
Reply With Quote #8

That link is totally irrelevant, and yes you are wrong. There is nothing special needed to get floats, but using the enum struct stuff can sometimes require you to explicitly state the tag, otherwise you'll get some tag mismatches.

It's all preference. If you like the struct-like syntax, then use it. Most plugins are only maintained by one person, so syntax should only matter to that one person.

The only thing I can think of off of the top of my head that could possibly break would be sizeof(), and I have no idea if it works or not, as I do not use that syntax.
__________________
fyren sucks

Last edited by sawce the snail; 07-01-2007 at 14:03.
sawce is offline
Zenith77
Veteran Member
Join Date: Aug 2005
Old 07-01-2007 , 15:44   Re: Structures in Pawn?
Reply With Quote #9

That link is to the plugin that has the code I was referencing to. But anyways, thanks for correcting me; post deleted.
__________________
Quote:
Originally Posted by phorelyph View Post
your retatred
Zenith77 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:37.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode