AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How can i save and load a string? (https://forums.alliedmods.net/showthread.php?t=128981)

Zezima14 06-07-2010 15:01

How can i save and load a string?
 
How can i save and load a string?

Example.

PHP Code:

new Var1[32], Var2[32

Var1[id] = // is a string... 
Var2[id] = // too is a string...  

// Save... 
public Save(id)

    
fvault_set_data(g_fvaultVar1[id], Var2[id]) 


// Load... 
public Load(id)

     
// how can i here load the string? i will try with parse and copy, but i cant :'( 


ty all ;)

fysiks 06-07-2010 17:23

Re: How can i save and load a string?
 
Var1[id] and Var2[id] are NOT strings.

Read this thread: http://forums.alliedmods.net/showthread.php?t=91207

HLM 06-07-2010 17:39

Re: How can i save and load a string?
 
Quote:

/**
* Retrieves data specified by a key
*
* @param vaultname Vault name to look in
* @param key Key name to look for the data
* @param data String which data will be copied to
* @param len Length of data
* @param timestamp The unix time of when the data was last set ( -1 if permanent data, 0 if old fvault version ) ( optional param )
* @return Returns 1 on success, 0 on failue.
*/
stock fvault_get_data(const vaultname[], const key[], data[], len, &timestamp=0)
PHP Code:

fvault_get_data(g_fvaultKEYNAMESTRINGSTRINGLEN

edit: I should probably do more than just post some copy-pasta, basically, STRING, is a variable with a length of STRINGLEN, so define a variable wherever you need this string (globally?) new string[128], then use fvault_get_data and STRING = string, and STRINGLEN = 128, there you go, that sum it up for ya?

Bugsy 06-07-2010 19:36

Re: How can i save and load a string?
 
I recommend reading the String section in the thread posted by fysiks.

Accessing a string within an array of strings and accessing a sub-string can look identical. It all depends on how the variable is defined.

Referencing a string with a supplied index ( Var1[ X ] ) can mean either:
1. You want to reference a full string within an array of strings
-- Works if the var is defined as Var1[ 33 ][ 50 ]
2. You want to access a sub-string within a single string.
-- Works if the var is defined as Var1[ 33 ]

Since you are specifying 'id' as your index I assume you are trying to store data on a per-player basis. To solve your problem, create an array of strings so each player has his own string to store info.

PHP Code:

new Var133 ][ 35 ]

//copy users name to the string array element 'id'
get_user_nameid Var1id ] , charsmaxVar1[] ) );
client_print( [...] , "hello %s" Var1id ] );

//copy "hello there" to the string array element 'id'
copyVar1id ] , charsmaxVar1[] ) , "hello there" ); 


Alucard^ 06-07-2010 19:40

Re: How can i save and load a string?
 
Code:
#include <amxmodx> #define PLUGIN  "New Plugin" #define AUTHOR  "Alucard" #define VERSION "0.0.1" new String1[] = "hey yo, whats up"; new String2[] = "i am a little turtle"; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);         register_clcmd("say /save", "HookCmdSave");     register_clcmd("say /load", "HookCmdLoad"); } public HookCmdSave(id) {     new szText[192];     formatex(szText, 191, "^"%s^" ^"%s^"", String1, String2);         write_file(file[], szText);     return PLUGIN_HANDLED; } public HookCmdLoad(id) {     new szText[192], var1[64], var2[64], iLine, iLen;         while(read_file(file[], iLine++, szText, 191, iLen) )     {         parse(szText, var1, 63, var2, 63);         break;     }         client_print(id, print_chat, "%s", var1);     client_print(id, print_chat, "%s", var2);         return PLUGIN_HANDLED; }

Is just an example, need more code...

Sry for not use fvault, nvault or whatever, i never read nothing about that things.

Zezima14 06-11-2010 00:51

Re: How can i save and load a string?
 
Quote:

Originally Posted by fysiks (Post 1202633)
Var1[id] and Var2[id] are NOT strings.

Read this thread: http://forums.alliedmods.net/showthread.php?t=91207

I know, I said the result of var1 is a string.

@thanks all.


All times are GMT -4. The time now is 05:15.

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