Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Chemin du dossier des habitants
- local inhabitantsFolder = "inhabitants/"
- -- Créer un habitant
- function createInhabitant(nickname, notes)
- local filePath = inhabitantsFolder .. nickname
- local file = fs.open(filePath, "w")
- file.write(notes)
- file.close()
- print("Habitant " .. nickname .. " créé.")
- end
- -- Rechercher un habitant par pseudo (lettres)
- function searchInhabitant(letter)
- for _, file in pairs(fs.list(inhabitantsFolder)) do
- if string.match(file, letter) then
- print("Trouvé: " .. file)
- local fileData = fs.open(inhabitantsFolder .. file, "r")
- print("Notes: " .. fileData.readAll())
- fileData.close()
- end
- end
- end
- -- Supprimer un habitant
- function deleteInhabitant(nickname)
- local filePath = inhabitantsFolder .. nickname
- if fs.exists(filePath) then
- fs.delete(filePath)
- print("Habitant " .. nickname .. " supprimé.")
- else
- print("L'habitant " .. nickname .. " n'existe pas.")
- end
- end
- -- Exemples d'utilisation
- createInhabitant("JohnDoe", "Notes pour JohnDoe.")
- searchInhabitant("John")
- deleteInhabitant("JohnDoe")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement