Search the Community
Showing results for tags 'tables'.
-
Hi Leadwerkers , Currently I am figuring out what would be the best way to save my game. What options there are for saving a table or varibles in general, and what options have you come up with? What I am working on at the moment was, to write a savedata table into a file like this and call it back with "dofile": return { someData = "Test"; someOtherData = "Tes2t"; } But this method is pretty tricky, not only have do you have to convert the variables into strings to save them, but it also is complicated and I think its no clean and fast solution because you have to work with the stream and filesystem command and "manually" write your data into a lua file. There is the System:SetProperty() command, but there you only can save strings as well. Are there any other commands Leadwerks offers? Another engine I worked before had a save command, where you can save any lua variable in (tables, strings, numbers everything) and then call it back. So tell me your attempt, what have you come up with? I want a system, where I just say: Save that variable and load that variable back on demand. If leadwerks does not offer such function itself I would be very thankful if you can link me tutorials, ideas or anything else which helps me building my own savesystem. Sorry if the english is not perfect Phoenix
-
When I fill a table with grid prefabs, I have two for loops in each other and this: table.insert(grid,gridPfb) System:Print(#grid) (#grid is the length of the table) It prints 100 times, each time its bigger,, because its being filled. But when I want to acces it from an other script , yes its a global table, like this: System:Print("STARTGRID : "..tostring(grid[1])) I get this in Output: STARTGRID : nil What could it be and how to fix it ? The length in runtime is also zero.
-
Removing items from Inventory after Use (Project Saturn scripts)
intog posted a topic in Programming
Hi everyone, I'm new here and somewhat new to programming (other than Actionscript 8 years ago and OpenSCAD modeling recently) I followed through Jorn's Project Saturn videos and now I'm wondering how I can finish the inventory scripts on my own. Jorn left off with an open function for using the item, but didn't go into how to remove the item after it's used. I'm guessing I need to remove that item's table from the inventory table but am a little lost on doing that and also since there are 3 scripts working together for the inventory, I'm not sure where this function would reside. Here is my bottle.lua script that I modified slightly to make it reusable for other items: Edit: Nevermind I fixed it on my own by adding a new variable to the table using the code in red: --this was the Bottle.lua script-- Script.InvIcon = "" -- path "Icon" "Tex file (*tex) :tex" Script.collectOnce = true -- bool "Collect once?" Script.reuseItem = true -- bool "Reuse Item?" Script.itemName = "Item" --string "Item Name" Script.useOnce = true -- bool "Use Once?" function Script:Use(player) -- allows hand use local playerInventory = player.script:GetInventory() -- reference player inventory if playerInventory == nil then error("no inventory") end System:Print("we got inventory") if not playerInventory:IsFull() then -- if inventory is NOT full, then: System:Print("we place the " ..self.itemName.. " into the inventory") local item = self:CreateInventoryItem() playerInventory:AddItemToInventory(item) if self.collectOnce then self.entity:Release() end end end function Script:CreateInventoryItem() item = InventoryItem:Create() item.name = self.itemName item.texture = Texture:Load(self.InvIcon) item.useOnce = self.useOnce item.UseInventoryItem = function() System:Print("You used the " .. self.itemName .. "!") end return item end Then I updated the use function in Inventory.lua (from the videos): if self.items.useOnce then self.items = nil end Thanks for your help!