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

String array won't compile


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 03-21-2013 , 04:10   String array won't compile
Reply With Quote #1

I haven''t been coding in pawn for a very long time, and as a result of this I am forgetting a lot of it.

One of the things is how to do a string array. What I need is to dynamically change a global string within my code:

PHP Code:
//Name of level
new gNameLevel[33]

gNameLevel[id] = "Instability" 
I need it to be set on specific players, not everyone, since they all may not have the same level, and I need to be able to print the name in other events/functions.

How can I go about this?
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 03-21-2013 , 04:57   Re: String array won't compile
Reply With Quote #2

You need to add a second dimension to your array which defines the max string length and then if your level name is hardcoded use copy()

Last edited by hornet; 03-21-2013 at 04:59.
hornet is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-21-2013 , 14:29   Re: String array won't compile
Reply With Quote #3

You shouldn't have a string for every player, it is inefficient. You should have an array (one cell for each player) that holds the index of the "level". Then, you can look up the appropriate string when you need to display it.
__________________
fysiks is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 03-21-2013 , 17:41   Re: String array won't compile
Reply With Quote #4

PHP Code:
new szString[33][33];

copy(szString[id],charsmax(szString[]),"Type your words where :)");


// The string contain 2 dimensions:
// 1 - for player id's
// 2 - for words (string)

// If you using this method use a string like szString[id] for specify the target and in charsmax using a second dimenssion: charsmax(szString[]) Adding [] :) 
Like this

Or


PHP Code:
new g_szNames[33][32];

public 
get_name(id)
{
   
get_user_name(id,g_szNames[id],charsmax(g_szNames[]));

__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 03-21-2013 at 17:45.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
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:11.


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