Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
« Previous 1 … 10 11 12 13 14 … 18 Next »
globaltables doesn't keep data between sf instances...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode
globaltables doesn't keep data between sf instances...
04-11-2015, 09:47 AM,
#1
Yuri6037 Offline
TSCM Member
***
Posts: 216
Threads: 45
Joined: Feb 2015
globaltables doesn't keep data between sf instances...
Hey Person,

I don't know if this is intended, but when you have a global table defined by one SF instance and then you try to read this value from another newly spawned SF instance, the vars set by the first SF instance are not kept inside the new SF instance.
That's a bit annoying, because well I plan on using those globaltables in the API I'm making for IntelliHUD. Indeed the api is intended to allow any seat entity to have special data like energy stats using my ZPM system to be renderable with the rest of the hud.
The problem is that if IntelliHUD is spawned after spawning chips using the IntelliHUD api, then data saved in globaltables before IntelliHUD spawn, are not kept inside the globals from IntelliHUD.

Note that those globals are server side only in how IntelliHUD manages things.

Is it intended to work this way, as it seams a bit weird for me ?
Can you fix it ?

Thanks by advance,
Yuri6037
Find
Reply
04-11-2015, 06:36 PM,
#2
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: globaltables doesn't keep data between sf instances...
Global tables do persist between instances. A lot of my chips would be broken if they didn't. Are you certain you're not redefining values and overwriting what was already there?
Find
Reply
05-11-2015, 11:43 AM,
#3
Yuri6037 Offline
TSCM Member
***
Posts: 216
Threads: 45
Joined: Feb 2015
RE: globaltables doesn't keep data between sf instances...
Here is the lib code (which adds variables to global tables) :
Code:
function intellihud.RegisterVehicle(VehicleEnt, data) if (not(IsValid(VehicleEnt))) then error("VehicleEnt must be a valid vehicle entity !") return end if (globaltables.global.IntelliHUD == nil) then globaltables.global.IntelliHUD = {} end globaltables.global.IntelliHUD[VehicleEnt:index()] = data end

And now the code that reads from it :
Code:
local function CheckPlayerSeats(p) if (globaltables.global.IntelliHUD == nil) then return end if (p:inVehicle()) then if (not(plysVeh[p] == p:vehicle())) then plysVeh[p] = p:vehicle() local e = p:vehicle() if (IsValid(e) and not(globaltables.global.IntelliHUD[e:index()] == nil)) then local data = globaltables.global.IntelliHUD[e:index()] if (IsValid(data.ZPM) and data.ZPM:class() == "starfall_processor") then plysData[p].VehData = {EnergyEntity = data.ZPM:getWirelink(), Name = data.Name, NameColor = data.NameColor} end end end if (not(plysData[p].VehData == nil)) then local en = plysData[p].VehData.EnergyEntity if (IsValid(en)) then if (not(plysData[p].VehData.PEnergy == en["P"])) then plysData[p].VehData.PEnergy = en["P"] plysForceSend[p] = true end end end elseif (IsValid(plysVeh[p])) then plysVeh[p] = nil plysData[p].VehData = nil plysForceSend[p] = true end end

The given function runs in a think hook to check if the player seats on a vehicle, and then retrieves if the vehicle exists on the defined IntelliHUD global table. However as I said, if you spawn the first function before the second one, the reader (second function) will not detect that the given vehicle is inside the table defined by first function. But if you inverse and spawn before the reader (second function), then it will detect any first function spawned.

You may also notice that the first function is not complete : indeed you need a special function that generates a table which contains an entity corresponding to ZPM starfall processor, a string name, and a color for the string name color.

To everyone, about this code, please don't copy it for your own projects, otherwise I will need to remove it from here. You can take the base idea if you want, just don't copy the code, and in plus that wouldn't help you understanding better how SF works by copying other's codes...

Thanks by advance,
Yuri6037
Find
Reply
05-11-2015, 01:30 PM,
#4
TheOneAndOnlyTee Offline
GMod Admin
Posts: 755
Threads: 47
Joined: Oct 2013
RE: globaltables doesn't keep data between sf instances...
Just saying, no one's gonna copy the code since it's of no use to anyone without >basic skill and i'm pretty sure we've all got our own methods/ideas about global tables

plus 'if' it is your code that's making the problem, copying it won't work lol.

Steam Profile
My Discord Server
Need help with E2 or SF? , just ask me and i'll try to help.
[Image: 98Dkcoz.gif]
Find
Reply
05-11-2015, 06:13 PM,
#5
Yuri6037 Offline
TSCM Member
***
Posts: 216
Threads: 45
Joined: Feb 2015
RE: globaltables doesn't keep data between sf instances...
Thanks for your post T-17, however the topic isn't on code sharing, that's just a note for everyone...

Anyways, have you any solutions ?
Find
Reply
05-11-2015, 06:56 PM,
#6
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: globaltables doesn't keep data between sf instances...
I used your code in the following way:

1. Spawned a chip containing:
local Vehicle = ents.self():isWeldedTo()
globaltables.global.IntelliHUD = {}
globaltables.global.IntelliHUD[ Vehicle:index() ] = { ZPM = ents.self() }

This chip is welded to a chair.

2. Spawned a second chip with:
local plysVeh = {}
local plysData = { [ ents.owner() ] = {} }
local plysForceSend = {}
local function CheckPlayerSeats(p)
if (globaltables.global.IntelliHUD == nil) then
return
end

if (p:inVehicle()) then
if (not(plysVeh[p] == p:vehicle())) then
plysVeh[p] = p:vehicle()
local e = p:vehicle()
if (IsValid(e) and not(globaltables.global.IntelliHUD[e:index()] == nil)) then
local data = globaltables.global.IntelliHUD[e:index()]
print( data, data.ZPM )
if (IsValid(data.ZPM) and data.ZPM:class() == "starfall_processor") then
plysData[p].VehData = {EnergyEntity = data.ZPM:getWirelink(), Name = data.Name, NameColor = data.NameColor}
end
end
end
if (not(plysData[p].VehData == nil)) then
local en = plysData[p].VehData.EnergyEntity
if (IsValid(en)) then
if (not(plysData[p].VehData.PEnergy == en["P"])) then
plysData[p].VehData.PEnergy = en["P"]
plysForceSend[p] = true
end
end
end
elseif (IsValid(plysVeh[p])) then
plysVeh[p] = nil
plysData[p].VehData = nil
plysForceSend[p] = true
end
end

timer.create( "bleh", 1, 0, function() CheckPlayerSeats( ents.owner() ) end )

When I sat down, I got a successful print message (of the table and the first chip). Getting out of the chair and sitting back down also worked. This leaves the only logical conclusion that there must be a problem in how you are setting up your vehicles that is outside of the code you've given here.
Find
Reply
06-11-2015, 02:58 AM,
#7
TheOneAndOnlyTee Offline
GMod Admin
Posts: 755
Threads: 47
Joined: Oct 2013
RE: globaltables doesn't keep data between sf instances...
Also just remebered, if you really want to get full help from Person you could use PM's instead.

Steam Profile
My Discord Server
Need help with E2 or SF? , just ask me and i'll try to help.
[Image: 98Dkcoz.gif]
Find
Reply
06-11-2015, 08:15 AM,
#8
Yuri6037 Offline
TSCM Member
***
Posts: 216
Threads: 45
Joined: Feb 2015
RE: globaltables doesn't keep data between sf instances...
Ok thanks Person, I'll try to investigate further on the issue, but it's strange that on your side it's working when spawning the vehicle before.
Find
Reply
06-11-2015, 01:00 PM,
#9
Yuri6037 Offline
TSCM Member
***
Posts: 216
Threads: 45
Joined: Feb 2015
RE: globaltables doesn't keep data between sf instances...
I found that realy strange, it works and sometimes not... That's weird...
Find
Reply
« Next Oldest | Next Newest »


  • View a Printable Version
Forum Jump:


Users browsing this thread: 1 Guest(s)
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.