Raised This Month: $51 Target: $400
 12% 

Horrible Pawn Features, Part 1


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BAILOPAN
Join Date: Jan 2004
Old 06-27-2012 , 19:14   Horrible Pawn Features, Part 1
Reply With Quote #1

Hi, everyone! Lately I've been studying the SourcePawn compiler. There are a bunch of interesting "features" - some of them are bugs - and, all of them are unsupported and will be removed. But at this specific point in time, they work, and they're amusing.

Today's horrible pawn features are: enums.

Have you ever wanted to make an enum where every index grew by a scale of 73 each time? No? Never? Well, you can:

Code:
enum (*= 73) {     Item1 = 1, // Value is 0     Item2,     // Value is 73     Item3,     // Value is 5,329     Item4      // Value is 389,017 }
Don't forget to initialize that first value to 1, otherwise everything will be 0! Note, you can also specify floats as the multiplier. For example, you can specify "1.5". Obviously this means Item2's value will be "1,069,547,520" and Item3 and Item4 will be 0. Makes sense, right?

You can also place floats inside enums. Did you forget to tag them? Don't worry! It doesn't matter. It's not type-checked.

Code:
enum {     A = 5.5,     B,     C }

Here, the value of "A" is 0x40b00000. "B" is 0x40b00001, and "C" is 0x40b00002. I hope that's clear.

You can also locally scope enums:
Code:
public method(a) {     if (a) {         enum MyEnum {             MyEnum_A,             MyEnum_B         }     } }

Cool, right? Hold up - what if you do this?

Code:
public method(a) {     if (a) {         enum MyEnum {   A, B    }     } else {         enum MyEnum {   A, B    }     } }

You get:
Code:
test.sp(4) : warning 201: redefinition of constant/macro (symbol "A")
__________________
egg
BAILOPAN is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 06-27-2012 , 20:00   Re: Horrible Pawn Features, Part 1
Reply With Quote #2

I really don't get this :

Quote:
Originally Posted by BAILOPAN View Post
[...] Note, you can also specify floats as the multiplier. For example, you can specify "1.5". Obviously this means Item2's value will be "1,069,547,520" and Item3 and Item4 will be 0. Makes sense, right?
Does it gives 0 because the 32 last bits resulting of "0011 1111 1100 0000 0000 0000 0000 0000"^2 = 0 ?

Also, I did use PrintToChatAll using 1069547520 * 1.5 and it gave : 1321156608 (wtf... ; %d) or 1604321280.000000.

How is the enum thing not having the same behaviour as the crappy int multiplication ?

Also why do I get something like 1321156608 from that 1.5 multiplication ?!

Otherwise, thanks for sharing.
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work

Last edited by RedSword; 06-27-2012 at 20:02.
RedSword is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 06-27-2012 , 20:06   Re: Horrible Pawn Features, Part 1
Reply With Quote #3

The float multiplier is probably read as normal integer by sourcepawn.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
BAILOPAN
Join Date: Jan 2004
Old 06-27-2012 , 20:20   Re: Horrible Pawn Features, Part 1
Reply With Quote #4

RedSword: Sorry, I was being facetious there ;) Yeah, it's total nonsense. berni's right. The compiler takes the bits that represent the float and interprets them as an integer.
__________________
egg
BAILOPAN is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 06-27-2012 , 23:21   Re: Horrible Pawn Features, Part 1
Reply With Quote #5

I want the part 2, this is so amusing.

How ever why sourcemod decided to use sourcepawn instead of c++ like amx? It could had compatibility plugin between hl1 and hl2 engine, that would be fun!

Last edited by Mathias.; 06-27-2012 at 23:22.
Mathias. is offline
Thraka
AlliedModders Donor
Join Date: Aug 2005
Old 06-27-2012 , 23:37   Re: Horrible Pawn Features, Part 1
Reply With Quote #6

I would so love a different scripting language.
Thraka is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-28-2012 , 04:45   Re: Horrible Pawn Features, Part 1
Reply With Quote #7

Quote:
Originally Posted by Black-Rabbit View Post
How ever why sourcemod decided to use sourcepawn instead of c++ like amx? It could had compatibility plugin between hl1 and hl2 engine, that would be fun!
AMX uses Pawn (which is where all these come from), SourcePawn is Pawn improved by the SourceMod team.
__________________

Last edited by asherkin; 06-28-2012 at 04:45.
asherkin is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 06-28-2012 , 09:47   Re: Horrible Pawn Features, Part 1
Reply With Quote #8

Oh, someone told me it was c++. Thank to know, but why there are structure and not in sourcepawn? It would be realy interressing.
Mathias. 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 05:58.


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