Recommended Posts

FurryEskimo    39

That also works!

There is another issue though.  The game IS spawning the original backpack, but it's being left off to the side of spawn, which means this method is spawning two backpacks..

The solution may be to simply tell the player they'll be given a backpack, but it's frustrating..

Share this post


Link to post
Share on other sites
TheSkylarr    18
1 minute ago, FurryEskimo said:

That also works!

There is another issue though.  The game IS spawning the original backpack, but it's being left off to the side of spawn, which means this method is spawning two backpacks..

The solution may be to simply tell the player they'll be given a backpack, but it's frustrating..

Are you absolutely sure OnLoad doesn't happen when you spawn? Thats the only reason I can see for it spawning 2 backpacks.

Share this post


Link to post
Share on other sites
FurryEskimo    39

@TheSkylarr

It's spawning two because one is in the 'starting inventory' code which makes the item displayed on the character select screen, and that item is spawned near spawn but never given to the player.  The code we've been discussing gives the player a backpack, but doesn't display it on the character select screen.

Edit:  I'm trying to find the code that causes images to appear on the inventory screen, but no luck yet.  I was thinking I might be able to force an image to appear.  This isn't a big deal whether I figure it out or not, but it is a little frustrating.

Edited by FurryEskimo

Share this post


Link to post
Share on other sites
IronHunter    569
2 hours ago, FurryEskimo said:

@TheSkylarr

It's spawning two because one is in the 'starting inventory' code which makes the item displayed on the character select screen, and that item is spawned near spawn but never given to the player.  The code we've been discussing gives the player a backpack, but doesn't display it on the character select screen.

Edit:  I'm trying to find the code that causes images to appear on the inventory screen, but no luck yet.  I was thinking I might be able to force an image to appear.  This isn't a big deal whether I figure it out or not, but it is a little frustrating.

remove the backpack from your prefab's starting inventory code and just add it to the TUNING.GAMEMODE_STARTING_ITEMS.DEFAULT.YOURCHARACTER this is what dictates what is visible in the character select screen. The item that is spawning is because your prefab's code still has the backpack in their.
 

Just make a different table for your start_inv that omits the backpack

Edited by IronHunter
  • Like 2

Share this post


Link to post
Share on other sites
FurryEskimo    39

@IronHunter
I've been studying how tables are handled in lua and making some progress with what I understand.
Tables Guide:  https://www.lua.org/pil/2.5.html
Flattening Guide:  https://rosettacode.org/wiki/Flatten_a_list

-- Defines starting inventory
if startinginventory == 1 then
	TUNING.GAMEMODE_STARTING_ITEMS.DEFAULT.FURRYESKIMO = {
		--Nothing
	}
elseif startinginventory == 2 then
	TUNING.GAMEMODE_STARTING_ITEMS.DEFAULT.FURRYESKIMO = {
		"heatrock",
	}
end

 

--Prepares a table of values for the character's starting inventory.
local start_inv = {}
for k, v in pairs(TUNING.GAMEMODE_STARTING_ITEMS) do
	start_inv[string.lower(k)] = v.FURRYESKIMO
end
local prefabs = FlattenTree(start_inv, true)

 

local master_postinit = function(inst)  --Set player's abilities here..
	--Sets starting inventory.
	inst.starting_inventory = start_inv[TheNet:GetServerGameMode()] or start_inv.default

Seems pretty simple.  A table is created using the player's 'GAMEMODE_STARTING_ITEMS', which is then also assigned as what's displayed on the character select screen.  The trouble I'm having is making an entirely new table.  The actual table is easy ( local start_inv_images = {} ) but how do get data into/out of the table without using 'GAMEMODE_STARTING_ITEMS'?  I think I know ( start_inv_images[k] = "heatrock", ) but I know there's more to it.  The whole section that originally used 'GAMEMODE_STARTING_ITEMS' to flatten the tree is, well I'm not entirely sure how to adapt it to the new table..  I'm still studying this, so maybe it'll be obvious soon why and how the table is being flattened, but for right now it's confused me.

Edit:  Maybe I just need to enter something other than 'default' in "TUNING.GAMEMODE_STARTING_ITEMS.DEFAULT.FURRYESKIMO = {" ?  I'm not sure where the 'tuning' values are all stored, but I'll give it a try regardless.  If I'm lucky 'default' won't be a special term, but one that can be Any term, and I can reuse the 'GAMEMODE_STARTING_ITEMS' code.  I suspect this won't work, but it's just an idea.

Edited by FurryEskimo

Share this post


Link to post
Share on other sites
FurryEskimo    39

@IronHunter
I can copy the contents, yes, but do I need to flatten the table afterwards?  Can I really just make a table, tell it to store this data like before, remove this code: 

--Prepares a table of values for the character's starting inventory.
local start_inv = {}
for k, v in pairs(TUNING.GAMEMODE_STARTING_ITEMS) do
	start_inv[string.lower(k)] = v.FURRYESKIMO
end
local prefabs = FlattenTree(start_inv, true)
	--Sets starting inventory.
	inst.starting_inventory = start_inv[TheNet:GetServerGameMode()] or start_inv.default

and replace it with something as simple as: 

--Prepares a table of values for the character's starting inventory.
local start_inv_images = {}
if startinginventory == 1 then
    start_inv_images[k] = {
		--Nothing
	}
elseif startinginventory == 2 then
    start_inv_images[k] = {
		"heatrock",
	}
end
	--Sets starting inventory.
      inst.starting_inventory = start_inv_images[k] or start_inv.default

It's that basic?

Edited by FurryEskimo

Share this post


Link to post
Share on other sites
FurryEskimo    39

@IronHunter
I've tried a few different attempts, and I think I understand the gist of what you've explained now, but the new table keeps failing to be created.  I've attached the character's prefab and the most recent error log.

if startinginventory == 1 then
	TUNING.TEST.DEFAULT.FURRYESKIMO = {
		--Nothing
	}
elseif startinginventory == 2 then
	TUNING.TEST.DEFAULT.FURRYESKIMO = {
		"heatrock",
	}
for k, v in pairs(TUNING.TEST) do
	start_inv[string.lower(k)] = v.FURRYESKIMO
end
:70: attempt to index field 'TEST' (a nil value) LUA ERROR stack traceback:

I'll keep trying, but I'm almost certain the error lies in the way I'm saving data in the new table.

furryeskimo.lua server_log_2021-02-28-19-56-18.txt

 

Update:  No luck so far.  I've tried over and over to do as you suggested (replace the 'TUNING.TABLE' part) but it hasn't worked, each time producing an error claiming the table name isn't defined.  I have managed to code tables, and insert/extract some information, sort of, but it appears to be, wrong..

local people = {  --Test code.
	{
		name = "Fred",
		address = "16 Long Street",
		phone = "123456"
	},
	{
		name = "Wilma",
		address = "16 Long Street",
		phone = "123456"
	},
	{
		name = "Barney",
		address = "17 Long Street",
		phone = "123457"
	}
}
	for k, v in pairs(people ) do  --Test code.  --Note: REMOVE.
		print("TABLE DUMP")
		print(k, v)
	end
[00:00:48]: TABLE DUMP	
[00:00:48]: 1	table: 0F12F3B0	
[00:00:48]: TABLE DUMP	
[00:00:48]: 2	table: 0F12F630	
[00:00:48]: TABLE DUMP	
[00:00:48]: 3	table: 0F12F3D8	

The table's data appears to be random, and changes each time I restart the server.
I get a similar result however when I print the table the game's using:

print("start_inv 2: ", start_inv.default)  --Test code

I'll keep trying to figure this out, but my instincts are telling me there's more going on here that I'm not aware of.

Edited by FurryEskimo

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now