orlando gonzalez Posted May 14, 2021 Share Posted May 14, 2021 hola yo hablo español ¿Cómo puedo crear una variable de contador que se guarde y cargue al cerrar el servidor? i no speak english How can I create a counter variable that is saved and loaded when shutting down the server? --------------------------------------------------------- "inst.components.helth.maxhealth" is = max hp character in theory "contador" It is my variable to create, when using it locally it is not saved, it is only restarted, not like the previous one that if it is modified because it is saved and loaded in the function -------------------------------------- local contador = contador or nil local function subirnivel(inst) if inst.components.health.maxhealth >= (1) and inst.components.health.maxhealth < (300) then inst.components.health.maxhealth = (inst.components.health.maxhealth + contador ) contador = contador * 0.9 end end ------------------------------------------- my funcion save and load local function onsave(inst, data) data.maxhealth = inst.components.health.maxhealth or nil end local function onpreload(inst, data) inst.components.health:SetMaxHealth(data.maxhealth) end ----------------------------------------------------------------------------- alguien tiene un ejemplo de como crear una variable para usarla como contador para poder guardar su valor y cargarlo sin que se reinicie en tiempo real o al cerrar y abrir el servidor o partida. someone has an example of how to create a variable to use as a counter to save its value and load it without rebooting in real time or when closing and opening the server or game. Link to comment https://forums.kleientertainment.com/forums/topic/129944-how-can-i-create-a-variable-for-my-function/ Share on other sites More sharing options...
Gleenus Posted May 14, 2021 Share Posted May 14, 2021 I will show you an example that can be applied to your case local function onsave(inst, data) local data = { myvar = inst.myvar, othermyvar = inst.othermyvar, } return next(data) ~= nil and data or nil end local function onpreload(inst, data) inst.myvar = data.myvar or inst.myvar inst.othermyvar = data.othermyvar or inst.othermyvar end This will save the variables "myvar" and "othermyvar" every c_save() (or night passing) And will load them when the server loads Link to comment https://forums.kleientertainment.com/forums/topic/129944-how-can-i-create-a-variable-for-my-function/#findComment-1460218 Share on other sites More sharing options...
orlando gonzalez Posted May 14, 2021 Author Share Posted May 14, 2021 3 hours ago, Gleenus said: I will show you an example that can be applied to your case local function onsave(inst, data) local data = { myvar = inst.myvar, othermyvar = inst.othermyvar, } return next(data) ~= nil and data or nil end local function onpreload(inst, data) inst.myvar = data.myvar or inst.myvar inst.othermyvar = data.othermyvar or inst.othermyvar end This will save the variables "myvar" and "othermyvar" every c_save() (or night passing) And will load them when the server loads tell me if i'm correct, a variable myvar is created to be saved in othermyvar so it can be saved just like the instantiated variable from maxhealth Link to comment https://forums.kleientertainment.com/forums/topic/129944-how-can-i-create-a-variable-for-my-function/#findComment-1460290 Share on other sites More sharing options...
Gleenus Posted May 14, 2021 Share Posted May 14, 2021 31 minutes ago, orlando gonzalez said: tell me if i'm correct, a variable myvar is created to be saved in othermyvar so it can be saved just like the instantiated variable from maxhealth No myvar and othermyvar are two distinct variables and they both are going to be saved and loaded No correlation between them You can see in the code that in any moment I set one variable to the other You can store as many variables you want using this code, but in this example I'm showing for two Link to comment https://forums.kleientertainment.com/forums/topic/129944-how-can-i-create-a-variable-for-my-function/#findComment-1460299 Share on other sites More sharing options...
orlando gonzalez Posted May 15, 2021 Author Share Posted May 15, 2021 10 hours ago, Gleenus said: No myvar and othermyvar are two distinct variables and they both are going to be saved and loaded No correlation between them You can see in the code that in any moment I set one variable to the other You can store as many variables you want using this code, but in this example I'm showing for two I am missing something to use the variable created in a process of another function, I need to give it a value to multiply or add "example var + var = 1, var + var = 2, var + var = 4, when closing it, 4 should be saved, when start the client again, load the value 4 and continue var + var = 8 depending on what I try to do, it doesn't give me an error, just disconnect the server client log [01:01:20]: ModIndex: Load sequence finished successfully. [01:01:20]: Reset() returning [01:01:22]: Attempting to send resume request [01:01:22]: ReceiveResumeNotification [01:01:22]: Deleting user: session/315A20BA3AF06222/A7IHJVFHRSEH/0000000001 [01:01:23]: WARNING! Could not find region 'kira.tex' from atlas '../mods/TheKira7/images/names_gold_kira.xml'. Is the region specified in the atlas? [01:01:23]: Looking for default texture '' from atlas '../mods/TheKira7/images/names_gold_kira.xml'. [01:01:23]: Error Looking for default texture in from atlas '../mods/TheKira7/images/names_gold_kira.xml'. [01:01:23]: WARNING! Could not find region 'kira.tex' from atlas '../mods/TheKira7/images/names_gold_kira.xml'. Is the region specified in the atlas? [01:01:23]: Looking for default texture '' from atlas '../mods/TheKira7/images/names_gold_kira.xml'. [01:01:23]: Error Looking for default texture in from atlas '../mods/TheKira7/images/names_gold_kira.xml'. [01:01:24]: WARNING! Could not find region 'kira.tex' from atlas '../mods/TheKira7/images/names_gold_kira.xml'. Is the region specified in the atlas? [01:01:24]: Looking for default texture '' from atlas '../mods/TheKira7/images/names_gold_kira.xml'. [01:01:24]: Error Looking for default texture in from atlas '../mods/TheKira7/images/names_gold_kira.xml'. [01:01:26]: Movement prediction enabled [01:01:26]: Deserializing tile data (425 x 425) [01:01:26]: Serializing user: session/315A20BA3AF06222/A7IHJVFHRSEH/0000000001 [01:01:44]: [Error] Dedicated server process terminated prematurely. [01:01:51]: Connection lost to 127.0.0.1|10999 <2294595244016901265> [01:01:51]: [Connect] PendingConnection::Reset(true) [01:01:51]: PushNetworkDisconnectEvent With Reason: "ID_CONNECTION_LOST", reset: true [01:01:51]: [IPC] Unregistering handler for signal #00000FDC [01:01:51]: [IPC] Unregistering handler for signal #00000FBC [01:01:51]: [IPC] Unregistering handler for signal #00000DBC [01:01:51]: [IPC] Unregistering handler for signal #00000FD4 [01:01:51]: [IPC] Unregistering handler for signal #00000F54 [01:01:51]: [IPC] Sending signal... #00000EFC [01:01:52]: [IPC] Unregistering handler for signal #00000FD8 [01:01:52]: [IPC] Unregistering handler for signal #00000F38 [01:01:52]: [IPC] Unregistering handler for signal #00000FA0 [01:01:52]: [IPC] Unregistering handler for signal #00000ECC [01:01:52]: [IPC] Unregistering handler for signal #00000F50 [01:01:52]: Serializing user: session/315A20BA3AF06222/A7IHJVFHRSEH/0000000001 [01:01:52]: [Steam] Game Connection terminated (2130706433|10999) [01:01:52]: [Shard] Stopping shard mode [01:01:52]: ModWorkshop::CancelDownloads clearing all unfinished downloads Link to comment https://forums.kleientertainment.com/forums/topic/129944-how-can-i-create-a-variable-for-my-function/#findComment-1460491 Share on other sites More sharing options...
Gleenus Posted May 15, 2021 Share Posted May 15, 2021 var + var = 1 << This syntax is weird Show your entire code and entire error log Both from the server-log and client-log Link to comment https://forums.kleientertainment.com/forums/topic/129944-how-can-i-create-a-variable-for-my-function/#findComment-1460638 Share on other sites More sharing options...
orlando gonzalez Posted May 15, 2021 Author Share Posted May 15, 2021 (edited) var = 0,5 Hace 47 minutos, Gleenus dijo: var + var = 1 << Esta sintaxis es extraña Muestra todo el código y el registro de errores completo Tanto del registro del servidor como del registro del cliente ¿Necesitas ver mi configuración? client_log.txt Edited May 15, 2021 by orlando gonzalez Link to comment https://forums.kleientertainment.com/forums/topic/129944-how-can-i-create-a-variable-for-my-function/#findComment-1460640 Share on other sites More sharing options...
Gleenus Posted May 15, 2021 Share Posted May 15, 2021 This is the client_log I also need the server_log and the full lua file Link to comment https://forums.kleientertainment.com/forums/topic/129944-how-can-i-create-a-variable-for-my-function/#findComment-1460702 Share on other sites More sharing options...
orlando gonzalez Posted May 16, 2021 Author Share Posted May 16, 2021 22 hours ago, Gleenus said: This is the client_log I also need the server_log and the full lua file I already managed to solve the problem of variables for my functions, I no longer have errors. but I can't get those variables to save correctly I try to save in local master_postinit = function (inst) the following "inst.SaveVariable = savevariable inst.CargarVariable = loadvariable " the following example is excellent On 5/14/2021 at 7:29 AM, Gleenus said: I will show you an example that can be applied to your case local function onsave(inst, data) local data = { myvar = inst.myvar, othermyvar = inst.othermyvar, } return next(data) ~= nil and data or nil end local function onpreload(inst, data) inst.myvar = data.myvar or inst.myvar inst.othermyvar = data.othermyvar or inst.othermyvar end This will save the variables "myvar" and "othermyvar" every c_save() (or night passing) And will load them when the server loads to make use in the functions of the variables use at the beginning inst.myvar = inst.myvar or (1) inst.myothermyvar = inst.myothermyvar or (1) and at the end of the function use return inst.myvar , inst.myothermyvar """the problem I have at the moment is the following.""" by making use of my variables and closing the client, the variables return to 1 and restart the cycle, because when the client closes the server it does not correctly save the values of the variables myvar and othermyvar, so they remain at 1 when reconnecting to the server. Can someone tell me what to do or how to do it since I don't know much and I want to learn? Link to comment https://forums.kleientertainment.com/forums/topic/129944-how-can-i-create-a-variable-for-my-function/#findComment-1460955 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now