View Single Post
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 01-02-2017 , 08:09   Re: Programming for starters
Reply With Quote #104

> //If values assigned during run-time (example, for storing player names or steamID's when they connect)
> new szString[number of strings][length of longest string]

You cannot change the number of strings on run time for static arrays. It its because they are static so its size must to be know on compile time.
If you want to change the size on run time, consider Dynamic Arrays or create a static array which should be big enough.
For example, if you want to save a string for each server player, you can declare a array like:
Code:
new players[ MAX_PLAYERS + 1 ][ MAXIMUM_STRING_SIZE_YOU_WILL_EVER_SAVE_HERE ]

> As, Quin had said there is always a 'NULL' character.

Yes, however here "0" is not 0, it is a string within the values as 44 and 0.
When you do "Hi", pawn null terminate it for. The string will with the values as 65, 53 and 0.
String is pawn are just a chain of numbers, where the last one is always 0.
The "0" you see in strings on your screen are not the value 0 on the string array, but something like
the value 46. It is because the actual 0 is used to flag the end of the string.


> Should "0" be there too?

No, you do terminate strings, not arrays of strings. You do need to null terminate if you write you string like this.
Code:
new szString[][] = { {'s','t','r','i','g','s','^0'}, {'0','^0'} }
But only each one of the strings, not create one last string empty.

I barely strached the surface of real contents here. If I would explain to you all, it would be written a complete tutorial.
But there is not need to me to do it, there are already very good ones out there. Search for tutorials about strings in pawn.
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 01-02-2017 at 08:11.
addons_zz is offline