AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   PAWN Objects (https://forums.alliedmods.net/showthread.php?t=183505)

Liverwiz 04-22-2012 13:52

PAWN Objects
 
Now.....i'm aware that pawn is a non-object oriented scripting language. So the closest thing you can get to that is either an array, including all the variables within the object, or a series of well documented variables.

Going along with the array way of doing things:

Code:

new object[3][34]
new i_obID = id
new sz_obName[32] = get_user_name(id)
new sz_obSteamID[34] = get_user_authid(id)

object[0] = i_obID
object[1] = sz_obName
object[2] = sz_obSteamID

Mind you this isn't exact code, i'm aware passing the ID can get me all this, i'm just using it all as the easiest example for those who aren't fully aware how objects in C++/Java work.

I suppose it all boils down to how to properly utilize a hanging(fringed} matrix....but pawn is so weird to me, and i'm out of proper practice with other languages.

i think it looks pretty, but when compiling the compiler throws errors like "array size do not match; or destination size too small"

ProIcons 04-22-2012 14:03

Re: PAWN Objects
 
try use this
new object[10][100];

Liverwiz 04-22-2012 14:36

Re: PAWN Objects
 
just attempted your concept of large array sizes:
PHP Code:

new object[4][64]
object[0][0] = id
object
[1][] = "ThatOneGuy" 

and threw me an error: invalid expression; assumed zero
referencing the "object[1][] " line

ProIcons 04-22-2012 14:40

Re: PAWN Objects
 
yes this can caused because you didn't specify anything on the 2nd dimmension of the array.

Try object[1]="ThatOneGuy";

Liverwiz 04-22-2012 14:43

Re: PAWN Objects
 
:shock: I could have sworn that didn't work when i tried it earlier.....but it compiled. Much thanks! will edit if i have any more problems when actually releasing it into the code i'm working on.

[EDIT] actually....while i have your attention:
why is it the compiler doesn't like this
Code:

const sz_command[] = "screenshot", i_ssCount = 32
is the 'const' declaration just a fancy way of making you hate your life?

ProIcons 04-22-2012 14:52

Re: PAWN Objects
 
new const sz_command[] = { "Screenshot" };

A working example is,

PHP Code:

new const HitPlaceStrings[][] = { "Generic","Head","Chest","Stomach","LeftArm","RightArm","LeftLeg","RightLeg" };
new const 
WeaponNames[][] = { 
    
"","P228 Compact","Shield","Schmidt Scout","He Grenade","XM1014 M4","C4 Bomb Explosive","Ingram MAC-10","Steyr AUG A1","Smoke Grenade","Dual Elite Berettas",
    
"FiveseveN","UMP 45","SG-550 Auto-Sniper","IMI Galil","Famas","USP .45 ACP Tactical","Glock 18C","AWP Magnum Sniper","MP5 Navy","M249 Para Machinegun",
    
"M3 Super 90","M4A1 Carbine","Schmidt TMP","G3SG1 Auto-Sniper","FlashBang","Desert Eagle .50 AE","SG-552 Commando","AK-47 Kalashnikov","Knife","ES P90" };
new const 
WeaponShortNames[][] = { 
    
"""weapon_p228""0""weapon_scout""weapon_hegrenade""weapon_xm1014""weapon_c4""weapon_mac10","weapon_aug""weapon_smokegrenade""weapon_elite"
    
"weapon_fiveseven""weapon_ump45""weapon_sg550","weapon_galil""weapon_famas""weapon_usp""weapon_glock18""weapon_awp""weapon_mp5navy""weapon_m249",
    
"weapon_m3""weapon_m4a1""weapon_tmp""weapon_g3sg1""weapon_flashbang""weapon_deagle""weapon_sg552","weapon_ak47""weapon_knife""weapon_p90" }; 


Liverwiz 04-22-2012 15:04

Re: PAWN Objects
 
its all about that 'new' qualifier..... :x grumble.....

however....thanks, man!

fysiks 04-22-2012 15:32

Re: PAWN Objects
 
Quote:

Originally Posted by Liverwiz (Post 1694542)
Code:

new object[3][34]
new i_obID = id
new sz_obName[32] = get_user_name(id)
new sz_obSteamID[34] = get_user_authid(id)

object[0] = i_obID
object[1] = sz_obName
object[2] = sz_obSteamID


You are trying to assign a scalar to an array. I'm sure you can see that that can't be correct :).

Also, you can't assign an array sized 32 to an array sized 34, IIRC. They have to be the same size. So, it is generally recommended to never assign arrays with "=" but to instead use copy().

Liverwiz 04-22-2012 16:58

Re: PAWN Objects
 
Quote:

Originally Posted by fysiks (Post 1694629)
Also, you can't assign an array sized 32 to an array sized 34, IIRC. They have to be the same size. So, it is generally recommended to never assign arrays with "=" but to instead use copy().

but using copy() in that manner makes for such ambiguous code....

and if you can't put a 32bit array in a 34, how would you propose to set up a fringed matrix? where there's isn't always the same number of columns in each row. or vise versa.

refer to the visual example below....

Code:

[00 01 02 03 04]
[10 11 12]
[20 21 22 23]


nikhilgupta345 04-22-2012 18:16

Re: PAWN Objects
 
Quote:

Originally Posted by Liverwiz (Post 1694708)
but using copy() in that manner makes for such ambiguous code....

and if you can't put a 32bit array in a 34, how would you propose to set up a fringed matrix? where there's isn't always the same number of columns in each row. or vise versa.

refer to the visual example below....

Code:

[00 01 02 03 04]
[10 11 12]
[20 21 22 23]


Don't think that's possible. I think the closest you could get to something like that is setting up a matrix with the maximum rows and columns that you would need, and then add ridiculous values to the spots that you want to be "empty" (just in case 0 is significant to you), so that you know which cell is not a "part" of the matrix. Or you could do something similar but create another 1-D matrix that holds the amount of columns in each row of the matrix and leave the empty cells as 0.


All times are GMT -4. The time now is 07:50.

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