ShadowMario / FNF-PsychEngine

Engine originally used on Mind Games mod
Apache License 2.0
1.15k stars 2.21k forks source link

Make a Lua callback that returns and splits a text file into separate list (table) items #6655

Closed BombasticTom closed 2 years ago

BombasticTom commented 2 years ago

What feature do you want to get added on the base engine?

READ BEFORE YOU SAY DO IT WITH LUA, I TRIED. IF I DIDN'T TRY I WOULDN'T HAVE OPENED THIS ISSUE!

so I tried combining the new getTextFromFile callback with a custom function to split the text lines into multiple list items it did work, but for some reason, the game would just crash.

Necessary code I wrote you'll need to know:

function mysplit (inputstr, sep)
    if sep == nil then
            sep = "%s"
    end
    local t={}
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
            table.insert(t, str)
    end
    return t
end

function onCreate()

        --local noteskins = {}
        noteskins = mysplit(getTextFromFile('./data/Saves/skins.txt') , '\n')

        options = {
            {'Player Noteskin', 'pnoteskin', 'string', 'Vanilla', noteskins},
            {'Opponent Noteskin', 'onoteskin', 'string', 'Vanilla', noteskins},
            {'Choose your Character', 'bfchar', 'string', 'BF', {'BF', 'Pico-Player', 'Eduardo'}},
            {'well well well', 'eduardo', 'bool'}
            --{'hitsound', 'bool', {'true', 'false'}, 'false'}, Do we need this anymore lmao?
        }

Since this plan didn't work, I would suggest to you to either fix the bug (or help me if it's not working because of me since I'm an idiot), or to make a new callback that separates list rows

(btw I know this code doesn't have end, that's because it's not the full code)

To test your sight, and reliability, please select the option of what should NOT be requested.

Stage Editor, 6K+ support, and winning icons.

cyn0x8 commented 2 years ago

the code looks right; either the game is crashing from the table or from getTextFromFile

BombasticTom commented 2 years ago

it's the table then i'll try and fix it then

BombasticTom commented 2 years ago

idk i think I'm doing something wrong image (placeholder is just a normal nave I gave) the upper text is the splitted txt file It just doesn't work with the noteskins table for some reason

BombasticTom commented 2 years ago

i know how to fix it

BombasticTom commented 2 years ago

image fixed :D

function mysplit(inputstr, sep)
    if sep == nil then
            sep = "%s"
    end
    local t={}
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
            table.insert(t, str)
    end
    return t
end

function onCreate()

        --noteskins = {
            --'Vanilla', 'DDR', 'Doki Doki Plus', 'Circles'
        --}

        noteskins = mysplit(getTextFromFile('./data/Saves/skins.txt'), '\n')

        options = {
            {'Player Noteskin', 'pnoteskin', 'string', noteskins[1], noteskins},
            {'Opponent Noteskin', 'onoteskin', 'string', noteskins[1], noteskins},
            {'Choose your Character', 'bfchar', 'string', 'BF', {'BF', 'Pico-Player', 'Eduardo'}},
            {'well well well', 'eduardo', 'bool'}
            --{'hitsound', 'bool', {'true', 'false'}, 'false'}, Do we need this anymore lmao?
        }

fixed code

yeeterongithub commented 2 years ago

@BombasticTom can you share the code (full code) cuz i wanna use these types of options

BombasticTom commented 2 years ago

https://gamebanana.com/mods/358754