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

Solved Multidimentional String Array Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
scorpius2k1
Senior Member
Join Date: Feb 2016
Old 11-20-2017 , 14:42   Multidimentional String Array Help
Reply With Quote #1

I am trying to setup a multidimentional string array like so:

PHP Code:
static String:sWeaponList[][] =
{
    {
"grenade_frag""Frag Grenade"},
    {
"rpg_missile""Rocket Launcher"},
    {
"smg1_grenade""SMG Grenade"},
    {
"slam""Slam"},
    {
"crowbar""Crowbar"},
    {
"stunstick""Stunstick"},
    {
"pistol""9mm Pistol"},
    {
"357""357 Magnum"},
    {
"smg1""SMG"},
    {
"shotgun""Shotgun"},
    {
"ar2""AR2 Rifle"},
    {
"combine_ball""Combine Ball"},
    {
"crossbow_bolt""Crossbow"},
    {
"physics""Physics"}
}; 
PHP Code:
PrintToChat(clientsWeaponList[2][0]); 
Would return "smg1_grenade". How can I access the second part which would be "SMG Grenade" ? If I try:

PHP Code:
PrintToChat(clientsWeaponList[2][1]); 
It returns "mg1_grenade", which is just cutting off part of the string instead of returning what I need.


Thanks for the help!
__________________
{__ PIRATES COVE __} ● HIGH-KILL Community | Stats ●
Half-Life 2: Deathmatch
66.151.244.149:27016 => CONNECT

Last edited by scorpius2k1; 12-06-2017 at 13:47.
scorpius2k1 is offline
ESK0
BANNED
Join Date: May 2014
Location: Czech Republic
Old 11-20-2017 , 15:06   Re: Multidimentional String Array Help
Reply With Quote #2

Use StringMap
ESK0 is offline
scorpius2k1
Senior Member
Join Date: Feb 2016
Old 11-20-2017 , 15:13   Re: Multidimentional String Array Help
Reply With Quote #3

Quote:
Originally Posted by ESK0 View Post
Use StringMap
Thanks for your reply ESK0, is there not a way to do it using just normal array functionality?
__________________
{__ PIRATES COVE __} ● HIGH-KILL Community | Stats ●
Half-Life 2: Deathmatch
66.151.244.149:27016 => CONNECT
scorpius2k1 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 11-20-2017 , 15:35   Re: Multidimentional String Array Help
Reply With Quote #4

It's a compiler bug that your sample code compiles. Your declaration should be static String:sWeaponList[][][] = ....
Fyren is offline
scorpius2k1
Senior Member
Join Date: Feb 2016
Old 11-20-2017 , 16:06   Re: Multidimentional String Array Help
Reply With Quote #5

Quote:
Originally Posted by Fyren View Post
It's a compiler bug that your sample code compiles. Your declaration should be static String:sWeaponList[][][] = ....
Thanks Fyren, here is code that should compile, using your suggestion:

PHP Code:
#include <sourcemod>

static String:sWeaponList[][][] =
{
    {
"grenade_frag""Frag Grenade"},
    {
"rpg_missile""Rocket Launcher"},
    {
"smg1_grenade""SMG Grenade"},
    {
"slam""Slam"},
    {
"crowbar""Crowbar"},
    {
"stunstick""Stunstick"},
    {
"pistol""9mm Pistol"},
    {
"357""357 Magnum"},
    {
"smg1""SMG"},
    {
"shotgun""Shotgun"},
    {
"ar2""AR2 Rifle"},
    {
"combine_ball""Combine Ball"},
    {
"crossbow_bolt""Crossbow"},
    {
"physics""Physics"}
};

public 
OnClientPutInServer(client)
{
    
PrintToChat(clientsWeaponList[0][0]);
    
PrintToChat(clientsWeaponList[0][1]);

    
PrintToChat(clientsWeaponList[1][0]);
    
PrintToChat(clientsWeaponList[1][1]);

    
PrintToChat(clientsWeaponList[2][0]);
    
PrintToChat(clientsWeaponList[2][1]);

Returns the first three indexes right, but after that, things get weird. Am I accessing the string indices correctly?

Output:

sWeaponList[0][0] => grenade_frag
sWeaponList[0][1] => Frag Grenade

sWeaponList[1][0] => rpg_missile
sWeaponList[1][1] => et Launcher

sWeaponList[2][0] => _grenade
sWeaponList[2][1] => Grenade


EDIT: It's like it starts returning the string starting at the 5th character on the improperly returned indices, for no apparent reason that I can see...?



__________________
{__ PIRATES COVE __} ● HIGH-KILL Community | Stats ●
Half-Life 2: Deathmatch
66.151.244.149:27016 => CONNECT

Last edited by scorpius2k1; 11-20-2017 at 16:27.
scorpius2k1 is offline
scorpius2k1
Senior Member
Join Date: Feb 2016
Old 11-20-2017 , 17:06   Re: Multidimentional String Array Help
Reply With Quote #6

I figured it out, I have to declare an array size on the last dimension like so:

PHP Code:
#include <sourcemod> 

static char sWeaponList[][][255] = 

    {
"grenade_frag""Frag Grenade"}, 
    {
"rpg_missile""Rocket Launcher"}, 
    {
"smg1_grenade""SMG Grenade"}, 
    {
"slam""Slam"}, 
    {
"crowbar""Crowbar"}, 
    {
"stunstick""Stunstick"}, 
    {
"pistol""9mm Pistol"}, 
    {
"357""357 Magnum"}, 
    {
"smg1""SMG"}, 
    {
"shotgun""Shotgun"}, 
    {
"ar2""AR2 Rifle"}, 
    {
"combine_ball""Combine Ball"}, 
    {
"crossbow_bolt""Crossbow"}, 
    {
"physics""Physics"
}; 

public 
OnClientPutInServer(client

    for(new 
0<= sizeof(sWeaponList); i++)
    {
        
PrintToChat(clientsWeaponList[i][0]); 
        
PrintToChat(clientsWeaponList[i][1]);
    }

Strange it cannot be dyamic, but this code works perfectly as intended.


Thanks for the replies guys, have a good one!

__________________
{__ PIRATES COVE __} ● HIGH-KILL Community | Stats ●
Half-Life 2: Deathmatch
66.151.244.149:27016 => CONNECT
scorpius2k1 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 12-06-2017 , 01:44   Re: Multidimentional String Array Help
Reply With Quote #7

Requiring you to set the last array size is, unfortunately, a different compiler bug, heh.

(Sorry for the slow response, was basically on vacation for two weeks.)
Fyren is offline
scorpius2k1
Senior Member
Join Date: Feb 2016
Old 12-06-2017 , 08:48   Re: Multidimentional String Array Help
Reply With Quote #8

Quote:
Originally Posted by Fyren View Post
Requiring you to set the last array size is, unfortunately, a different compiler bug, heh.

(Sorry for the slow response, was basically on vacation for two weeks.)
No worries at all. It seems to be my luck finding bugs lol. Hope vacation was good, thanks again for your help.
__________________
{__ PIRATES COVE __} ● HIGH-KILL Community | Stats ●
Half-Life 2: Deathmatch
66.151.244.149:27016 => CONNECT
scorpius2k1 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 11:31.


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