AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Saving in arrays (https://forums.alliedmods.net/showthread.php?t=141302)

reinert 10-22-2010 06:50

Saving in arrays
 
Is it possible to save a text message in arrays like:

PHP Code:

new something "" 

then in some commands add something like this:

PHP Code:

something "hi you are an idiot" 

or
PHP Code:

something "hi you are an dumbass" 

then show that in menu:

PHP Code:

formatex(title511"message of the hour:^n\y ^"%s^"^n\w."something

and also: display a message to player:
PHP Code:

client_print(idprint_chat"moth: ^"%s^", something) 


Schwabba 10-22-2010 07:24

Re: Saving in arrays
 
failpost xD

reinert 10-22-2010 07:57

Re: Saving in arrays
 
what for I need array "i" ?

maybe could explain me more ?

why not just

something[] = "blabla" or something = "blabla"

Arkshine 10-22-2010 08:00

Re: Saving in arrays
 
You can declare a string like that : new something[] = "hi you are an idiot" ;

But if you string is already declared somewhere, you can't copy text directly, you need to use copy().

reinert 10-22-2010 08:19

Re: Saving in arrays
 
So how can I change my something result from "hi you are an idiot" to "hi you are a dumbass"


new reason[] = "";

Arkshine 10-22-2010 08:25

Re: Saving in arrays
 
use copy().

new reason[] = ""; <== If you declare a variable without string, you need to specify the max length. new reason[ 128 ]; for example.

There are already severals tutorials about such basic knowledge. Start to read that.

http://forums.alliedmods.net/showthread.php?t=94381
http://forums.alliedmods.net/showthread.php?t=91207

hleV 10-22-2010 13:51

Re: Saving in arrays
 
Quote:

Originally Posted by Arkshine (Post 1331601)
But if you string is already declared somewhere, you can't copy text directly, you need to use copy().

You can, as long as the other string has the same number of elements.
PHP Code:

new g_szString1[] = "txt1"// 5 elements
new g_szString2[5]; // Or sizeof(g_szString1)
 
g_szString2 g_szString1;
g_szString1 "txt2"


fysiks 10-22-2010 18:24

Re: Saving in arrays
 
Quote:

Originally Posted by hleV (Post 1331785)
You can, as long as the other string has the same number of elements.
PHP Code:

new g_szString1[] = "txt1"// 5 elements
new g_szString2[5]; // Or sizeof(g_szString1)
 
g_szString2 g_szString1;
g_szString1 "txt2"


But, not recommended at any time.

Arkshine 10-22-2010 18:34

Re: Saving in arrays
 
@hleV ; You don't need to say that to me, but I don't see how it can be useful to a beginner, like said fysiks that's not recommended and it would have been confusing for him. He will discover that naturally after having more knowledge.

reinert 10-23-2010 03:53

Re: Saving in arrays
 
By the way, I wan't to ask, if I use menu with player list in it. When one admin selects for example player1, then there is another menu, what do you want to do with him... And at the same time another admin selects player2... I'm saving players like new tempid; So when first admin chooses an action Does action will be applied to Player1 what he selected, or player2 which was selected last and saved in tempid array.


All times are GMT -4. The time now is 10:23.

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