AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Structures in Pawn? (https://forums.alliedmods.net/showthread.php?t=57190)

Afrow UK 06-30-2007 06:53

Structures in Pawn?
 
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

Sylwester 06-30-2007 06:56

Re: Structures in Pawn?
 
check this: http://forums.alliedmods.net/showthread.php?t=26634

Afrow UK 06-30-2007 07:18

Re: Structures in Pawn?
 
Cheers :)

Afrow UK 06-30-2007 07:20

Re: Structures in Pawn?
 
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

Zenith77 06-30-2007 11:03

Re: Structures in Pawn?
 
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 ;).

P34nut 06-30-2007 11:06

Re: Structures in Pawn?
 
I like them, I use them and I have never had any problems with them

sawce 07-01-2007 01:13

Re: Structures in Pawn?
 
Quote:

Originally Posted by Zenith77 (Post 496534)
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?

sawce 07-01-2007 14:01

Re: Structures in Pawn?
 
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.

Zenith77 07-01-2007 15:44

Re: Structures in Pawn?
 
That link is to the plugin that has the code I was referencing to. But anyways, thanks for correcting me; post deleted.


All times are GMT -4. The time now is 21:24.

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