-
-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In memory only variables #1049
Comments
Just for clarification, do you mean that the "-" prefixed variables would be temporary to that instance of server uptime (i.e. until a restart/shutdown) but still globally scoped otherwise? If so that definitely sounds super useful for vars that only need to be set for a couple of ticks but or so but also need to persist outside of an event. I encounter that more often than you'd expect with the type of stuff I work on. I'll label as both enhancement and bug since I think it fits both parameters but if anyone else (@Snow-Pyon ) thinks it could be labelled better (perhaps as just enhancement) then feel free! |
Exactly. They would just be global variables that are lost once skript/the server is stopped or reloaded. Some examples where you might use it:
In fact, many if not most variables should be of that type. The user should make the decision whether a variable needs saving or not. I chose the "-" as a prefix because it is similar to the underscore used for local variables. So you would have these four variable types:
I am against giving the user a choice which prefix to use for global variables as it would make sharing scripts more difficult. |
That sounds so unbelievably useful!! Hope to see someone tackle it soon. |
I think I'll tackle this. |
@Syst3ms look at my first post. It links to the class and method where you would have to implement it. Then just add a config option to enable/disable it. |
I already did that, see the memory-variables branch on my fork. I added the check in a few more places just to make sure, but it's only missing the config option |
This was talked about a long time ago back when Njol still developed. It should be a storage option rather than an option altogether, that way the user can define the configuration pattern. Good for backward compatibility as well, just in case the user already has a database that uses the |
I am against using a pattern for this. The reason is that everyone will choose a different one, making scripts less compatible with each other. Also, there is no reason to have different patterns. It is really just an on/off choice. If everyone uses his own pattern it will become a huge mess. Furthermore it is easier to read other people's code and give support if everyone can easily see what is going on. In fact, in the current config file it is already suggested that you should use the following variable pattern for unsaved variables:
The problem is, as I explained in the initial post, that it only prevents variables from being loaded from the database but not from being saved. This is pretty pointless and that is why I suggested that it should get fixed (Suggestion 2). Telling everyone that they should use the |
This must be implemented, seriously. Also, the |
Easier said then done, I'll look for a fix but no promises here, the current variable system is kinda messy but not as much as the parser so we'll see. |
I actually made this, but because of major Git fuckup and lack of time, I abandoned it and the code is nowhere to be found. |
Good news, I think I found the bug why the patterns are not working properly. It seems that everything works perfectly fine and variables are correctly saved (or not saved) as long as the server is running. Once you stop the server variables get saved all over the place. I found the issue in the FlatFileStorage file. The save() method is not working as it should. The issue is that it does not correctly check whether the variable should be saved in that file or in another one:
Here is a possible fix for the method:
Edit: Don't blame me for the weird indentation something went wrong... |
With the merging of #1073, shall I close this? |
No, this should still be added |
I think you can close it. @HYPExMon5ter I fixed variable patterns and variables are now saved to the right databases (see #1073). So if you want to have in memory only variables I suggest that you change the variable pattern for all your databases from |
Suggestion 1
All variables starting with a "-" sign will not be saved in a database. A config option can be added to allow/prevent this behaviour (for backwards compatibility).
Suggestion 2
Fix the variable pattern matching to prevent saving of variables that do not match any pattern.
Issue
The current behaviour of Skript is to save all non-local variables in a database. Even variables that do not match any pattern specified in the config file are written to the database (the last one you specify). They are only removed once the variable file is reloaded.
Suggestion 1 would add an easy way to prevent all the outlined issues. The (probably) easiest solution would be to check for the prefix in the setVariable method in the Variables.class and simply not call the saveVariableChange method if the prefix is present.
Suggestion 2 could also be considered as a bug fix.
The text was updated successfully, but these errors were encountered: