Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Load List Example
- // by MissEshock2002
- // This script, from https://ss.deviatenow.com, is protected by this licence:
- // CC0
- setInfos(9, "Load List Example",
- "Load List from 'data.properties'",
- "MissEshock2002",
- "v1.0", 0x222222, "en", ["example", "tutorial"]);
- String SCRIPTNAME = "LoadListExample"
- List exampleIntList = [1, 2, 3]
- List exampleFloatList = [1.2, 3.4, 5.6]
- List exampleStringList = ["A", "B", "C"]
- List exampleBoolList = [true, true, false]
- save(SCRIPTNAME + ".exampleIntList", exampleIntList)
- save(SCRIPTNAME + ".exampleFloatList", exampleFloatList)
- save(SCRIPTNAME + ".exampleStringList", exampleStringList)
- save(SCRIPTNAME + ".exampleBoolList", exampleBoolList)
- String savedListsText = "Saved lists: " +
- "\nexampleIntList = " + exampleIntList +
- "\nexampleFloatList = " + exampleFloatList +
- "\nexampleStringList = " + exampleStringList +
- "\nexampleBoolList = " + exampleBoolList
- def loadIntegerList = { String scriptName, String listName ->
- // return list with Integers from 'data.properties'
- List tempList = []
- int listIndex = 0
- while (true) {
- def listItem = loadInteger(SCRIPTNAME + "." + listName + "." + listIndex)
- if (listItem != null) tempList.add(listItem)
- else break
- listIndex++
- }
- return tempList
- }
- def loadFloatList = { String scriptName, String listName ->
- // return list with Floats from 'data.properties'
- List tempList = []
- int listIndex = 0
- while (true) {
- def listItem = loadFloat(SCRIPTNAME + "." + listName + "." + listIndex)
- if (listItem != null) tempList.add(listItem)
- else break
- listIndex++
- }
- return tempList
- }
- def loadStringList = { String scriptName, String listName ->
- // return list with Strings from 'data.properties'
- List tempList = []
- int listIndex = 0
- while (true) {
- def listItem = loadString(SCRIPTNAME + "." + listName + "." + listIndex)
- if (listItem != null) tempList.add(listItem)
- else break
- listIndex++
- }
- return tempList
- }
- def loadBooleanList = { String scriptName, String listName ->
- // return list with Booleans from 'data.properties'
- List tempList = []
- int listIndex = 0
- while (true) {
- def listItem = loadBoolean(SCRIPTNAME + "." + listName + "." + listIndex)
- if (listItem != null) tempList.add(listItem)
- else break
- listIndex++
- }
- return tempList
- }
- def loadList = { String scriptName, String listName ->
- // return list with listName from 'data.properties'
- // detects data type
- List listOfStrings = []
- int listIndex = 0
- while (true) {
- def listItem = loadString(SCRIPTNAME + "." + listName + "." + listIndex)
- if (listItem != null) listOfStrings.add(listItem)
- else break
- listIndex++
- }
- List tempList = []
- if (listOfStrings.every { it -> it.isNumber() }) {
- if (listOfStrings.every { it -> it.isInteger() }) {
- listOfStrings.each { it -> tempList.add(it.toInteger()) }
- return tempList
- } else if (listOfStrings.any { it -> it.isFloat() }) {
- listOfStrings.each { it -> tempList.add(it.toFloat()) }
- return tempList
- }
- } else if (listOfStrings.every { it -> (it in ["true", "false"]) }) {
- listOfStrings.each { it ->
- if (it == "true") tempList.add(true)
- else tempList.add(false)
- }
- return tempList
- } else {
- return listOfStrings
- }
- }
- def getListOverview = { list ->
- return savedListsText +
- "\n\nLoaded list: " +
- "\nlist = " + list.toString() +
- "\nlist.size() = " + list.size() +
- "\nlist.isEmpty() = " + list.isEmpty() +
- "\nlist[0].getClass() = " + list[0].getClass()
- }
- List menuList = ["Load Integer List", "Load Float List", "Load String List", "Load Boolean List"]
- List loadedList = []
- boolean endLoop = false
- while (!endLoop) { // loop repeats till endLoop = true
- show("In this example lists are load by known data type.\n" +
- "The items in the saved list must have the same data type: Integer, Float, String or Boolean.\n\n" +
- getListOverview(loadedList))
- int sel = getSelectedValue(null, menuList + "Next")
- if (sel == 0) {
- loadedList = loadIntegerList(SCRIPTNAME, "exampleIntList")
- } else if (sel == 1) {
- loadedList = loadFloatList(SCRIPTNAME, "exampleFloatList")
- } else if (sel == 2) {
- loadedList = loadStringList(SCRIPTNAME, "exampleStringList")
- } else if (sel == 3) {
- loadedList = loadBooleanList(SCRIPTNAME, "exampleBoolList")
- } else {
- endLoop = true
- }
- }
- endLoop = false
- while (!endLoop) { // loop repeats till endLoop = true
- show("In this example lists are load by unknown data type. The data type is guessed by the items in the list.\n" +
- "The items in the saved list must have the same data type: Integer, Float, String or Boolean.\n\n" +
- getListOverview(loadedList))
- int sel = getSelectedValue(null, menuList + "End")
- if (sel == 0) {
- loadedList = loadList(SCRIPTNAME, "exampleIntList")
- } else if (sel == 1) {
- loadedList = loadList(SCRIPTNAME, "exampleFloatList")
- } else if (sel == 2) {
- loadedList = loadList(SCRIPTNAME, "exampleStringList")
- } else if (sel == 3) {
- loadedList = loadList(SCRIPTNAME, "exampleBoolList")
- } else {
- endLoop = true
- }
- }
- show("- End of Script -")
Add Comment
Please, Sign In to add comment