TheM3ss Posted August 13, 2021 Share Posted August 13, 2021 (edited) Hi, I've looked in the foruns trying to find something that might contain a solution for what i want to do. Is a simple mod intended only to allow me to export some info from the game into text files to be used with OBS. I want to get the info on the char to text files with: Time survived, number of zombies killed and his traits. The number of kills was easy and just browsing through the documentation i was able to do it in a simple way ( it may not be the best way but it works ) function zedkills() local player = getSpecificPlayer(0); local zedskilled = player:getZombieKills(); local writer = getFileWriter("zkills.txt", true, false); writer:write(tostring(zedskilled)); writer:close(); end So from what i read i was supposed to be able to get all the traits into a Variable - local CharTraits = player:GetTraits(); which should give me a arraylist with the traits i assume, but no matter what method i use to try and convert the arraylist to string and dump it into a file i always get an error saying Exception thrown java.lang.RuntimeException: attempted index: write of non-table: null at KahluaThread.tableget line:1689.. I know nothing of java and i am most likely doing something dumb and obviously wrong. So if possible, i would like to know the proper way to get the character info from the player object and to dump it into a text file. Googled everywhere and everything i could think off but after a week frying my brain over this i have made no progress and i think is time to ask for help with this subject. Edited August 13, 2021 by TheM3ss Link to comment Share on other sites More sharing options...
Hermago Posted November 20, 2022 Share Posted November 20, 2022 Hello. My english is poor, sorry, but i understand your problem and suggest put a number if answer is nothing or put some number before. Error comes when try to translate some null (nil) to string. Examples: function zedkills() local player = getSpecificPlayer(0); if player:getZombieKills() ~= nil then local zedskilled = player:getZombieKills(); else local zedskilled = 0; end local writer = getFileWriter("zkills.txt", true, false); writer:write(tostring(zedskilled)); writer:close(); end or something like this function zedkills() local player = getSpecificPlayer(0); local zedskilled = player:getZombieKills(); if zedskilled ~= nil then local zedskilled = player:getZombieKills(); else local zedskilled = 0; end local writer = getFileWriter("zkills.txt", true, false); writer:write(tostring(zedskilled)); writer:close(); end or this function zedkills() local player = getSpecificPlayer(0); local zedskilled = 0; if player:getZombieKills() ~= nil then local zedskilled = player:getZombieKills(); end local writer = getFileWriter("zkills.txt", true, false); writer:write(tostring(zedskilled)); writer:close(); end i suggest number 2 becouse only need a copy paste Link to comment Share on other sites More sharing options...
TheM3ss Posted January 2, 2023 Author Share Posted January 2, 2023 Very good tip, i have "finished" the mod but can always improve on it... i have little experience to lua and mostly wrote the mod while fishing for errors and learning as i progressed, will apply your suggestion to the existing mod. Thank you. Link to comment 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