[Include] y_svar - Save and load data with no effort at all!
#1

This has been a feature of YSI for a long time, but a recent update has made it even more useful by supporting a wider range of variables. The system is fully documented on the YSI wiki, but a brief description is also given below:

http://ysi.wikia.com/wiki/Library:YSI\y_svar

To save and load data using y_svar, you just need to declare the array in which the data will be stored! You need to do that anyway for all data, but with other systems you then need to actually write the save and load code too. This system does away with all that simply by replacing "new" with "svar":

pawn Code:
#define MODE_NAME "SavedText"
#include <YSI\y_svar>

svar gSavedText[200];

public OnGameModeInit()
{
    printf("Saved Text: %s", gSavedText);
}

YCMD:settext(playerid, params[], help)
{
    if (help) return SendClientMessage(playerid, 0xFF0000AA, "Sets the saved text");
    strcpy(gSavedText, params);
    return 1;
}
That will save the variable called "gSavedText" when the mode ends, and reload it when the mode starts. There is NO complex file/database code required AT ALL - it is all done behind the scenes.

To download this library, just get YSI from the main topic:

https://sampforum.blast.hk/showthread.php?tid=321092
Reply
#2

Any benchmarks for using this against other types of saving/loading systems?
Reply
#3

No, speed isn't really the focus of this system, just usefulness and ease. Anyway, given that the loading/saving doesn't run while your mode is running, only at startup/closing I'm not sure why benchmarks are even relevant.
Reply
#4

Ah, that makes complete sense. I apologize for my idiocy, it's been a long day.
Reply
#5

Wow, I wish I'd have known of this earlier! Things like my admin system will be so much less of a hassle. Definitely going to take advantage of this.
Reply
#6

So basically this includes replacing the normal variables but added the function that when you restart / server closes the information contained in it be saved?

[SORRY FOR MY ENGLISH ^^]
Reply
#7

Yes, in fact within code they are just normal variables. But get saved automatically.
Reply
#8

It's fantastic. REP+
Reply
#9

If anyone cares about how the very cryptic strings are generated to store this data, I just wrote it up here:

http://ysi.wikia.com/wiki/Base_64_Encoding
Reply
#10

Ok I am trying tu use this in a filterscript. I have
#define FILTERSCRIPT
#define MODE_NAME "Sheeld"
#include <YSI\y_svar>
#include <YSI\y_iterate>
at the top of my script. But the variables don't save.
Is it incompatibile with FS or am i doing somethyng wrong?
Reply
#11

It shouldn't be, is that MODE_NAME unique and different to the main GM?
Reply
#12

The GM is not using ISY at all. I have found your great work only few days ago. Also there is no new file in scriptfiles that i could see.
Reply
#13

How do you close the filterscript?
Reply
#14

I was just messing with this a bit and I couldn't get it to work so I ran your code just how it was in the first post, and it isn't printing anything at all in the console after i do /settext and restart the server.

pawn Code:
#include <a_samp>
#include <YSI\y_commands>
#define MODE_NAME "SavedText"
#include <YSI\y_svar>

svar gSavedText[200];
main(){}
public OnGameModeInit()
{
    printf("Saved Text: %s", gSavedText);
}

YCMD:settext(playerid, params[], help)
{
    if (help) return SendClientMessage(playerid, 0xFF0000AA, "Sets the saved text");
    strcpy(gSavedText, params);
    return 1;
}
Reply
#15

Do you have write permissions and the correct folder structure (included in YSI)?
Reply
#16

Quote:
Originally Posted by Y_Less
View Post
Do you have write permissions and the correct folder structure (included in YSI)?
What do you mean by write permissions? If you mean am i able to write files in general then yes default file functions write. And I am pretty sure I have the correct folder structure as i have the whole YSI library installed
Reply
#17

OK it seems that you need a folder YSI in scriptfiles (always a good idea to reed the server log ). And my custom testing code worked.
Code:
#define MODE_NAME   "SVarTest"
#include <a_samp>
#include <YSI\y_svar>
#include <YSI\y_timers>

svar Skuska[1];

timer Random[2000]()
{
	print("========================================");
    printf("Data: %d",Skuska[0]);
	if(Skuska[0] == 0) Skuska[0] = random(999) + 1;
	printf("Data2: %d",Skuska[0]);
}

public OnGameModeInit()
{
    defer Random();
	return 1;
}
But my filterscript is not working. I am using enum in it.
Code:
#include <a_samp>
#include <exis>
#include <h_colors>

#define FILTERSCRIPT
#define MODE_NAME "Sheeld"
#include <YSI\y_svar>
#include <YSI\y_iterate>
...
enum SERVER_INFO
{
	DialogShift,
	BanSystem,
	KickS,
	Setup,
	Mode,
	Dni,
	Hodin,
	Minut
}

svar Server[SERVER_INFO];
But it had at least created the file inn scriptfiles

EDIT: I tried both unloading the FS as rcon and using exit in console.
EDIT2: Ok i have probably messed up the dialogs
Reply
#18

Ok and now the funny part. I included y_timers and it magicly started working
Well the y_svar is probably missing some include or definition that is in y_timers
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)