Jump to content
  • 0

How to update seek bar value with user input


Platonic

Question

Posted

When user sets the value of the seekbar, the seekbar must display the new values when user opens the gg.prompt.

The script partly works, but i receive an error the moment the second menu becomes nil.

function boolCheck()
  menuHasBeenUsed = false
  loopMenu = 0
end
boolCheck()

function loopCheck()
  charLoop = 0
  gameSpdLoop = 0
  objSpdLoop = 0
  jmpLoop = 0
  charSizeLoop = 0
end
loopCheck()

function menu()
  menuBool = false
end
menu()

function menu()
  menuBool = false
end
menu()

function START()
  if menuBool == false then
    speed = gg.prompt
    (
      {'Animation Speed | default value = 1 | [1; 10]', 'Game Speed | default value = 1  [1; 10]', 'Playerobject Speed | default value = 1  [1; 10]', 'Jump hack', 'Player size | default value = 1 [1;10]'},
      {[1]='1', [2]='1', [3]='1', [5]='1'},
      {'number', 'number', 'number', 'checkbox', 'number'}
    )
  elseif menuBool == true then
        speed = gg.prompt
    (
      {'Animation Speed | default value = 1 | [1; 10]', 'Game Speed | default value = 1  [1; 10]', 'Playerobject Speed | default value = 1  [1; 10]', 'Jump hack', 'Player size | default value = 1 [1;10]'},
      {[1]=speed[1], [2]=speed[2], [3]=speed[3], [5]=speed[5]},
      {'number', 'number', 'number', 'checkbox', 'number'}
    )
  end
  
  menuBool = true
  
  if speed == nil then
    noselect()
  else
    
    if speed[1] then
      menuHasBeenUsed = true
      charLoop = charLoop + 1
      if charLoop <= 1 then
        characterAnim()
      end
      for i = 1, #characterAnimation do
        characterAnimation[i]["value"] = speed[1]
      end
      gg.setValues(characterAnimation)
    end
    
    if speed[2] then
      menuHasBeenUsed = true
      gameSpdLoop = gameSpdLoop + 1
      if gameSpdLoop <= 1 then
        fullGameSpeed()
      end
      for i = 1, #gameSpeedFull do
        gameSpeedFull[i]["value"] = speed[2]
      end
      gg.setValues(gameSpeedFull)
    end
    
    if speed[3] then
      menuHasBeenUsed = true
      objSpdLoop = objSpdLoop + 1
      if objSpdLoop <= 1 then
        charsObjectSpeed()
      end
      for i = 1, #characterObjectSpeed do
        characterObjectSpeed[i]["value"] = speed[3]
      end
      gg.setValues(characterObjectSpeed)
    end
    
    if speed[4] then
      menuHasBeenUsed = true
      for i = 1, #jumpCount do
        jumpCount[i]["value"] = "0"
        jumpCount[i]["freeze"] = true
        gg.addListItems(jumpCount)
      end
    end
    
    if speed[5] then
      menuHasBeenUsed = true
      charSizeLoop = charSizeLoop + 1
      if charSizeLoop <= 1 then
        charsObjectSize()
      end
      for i = 1, #characterObjectSize do
        characterObjectSize[i]["value"] = speed[5]
      end
      gg.setValues(characterObjectSize)
    end
    print(speed)
  end
end

function noselect()
  gg.toast('You not select anything')
end

START()
while (true) do
  if gg.isVisible() then
    gg.setVisible(false)
    START()
  else
    if menuHasBeenUsed == true then
      jumpPointer = gg.getValues(jumpPointer)
      valueCheck()
    end
  end
  gg.sleep(200) 
end

Error:

Script error: luaj.o: /storage/emulated/0/Pictures/LearningLua.lua:209
`      {[1]=speed[1], [2]=speed[2], [3]=speed[3], [5]=speed[5]},`
attempt to index ? (a nil value) with key '1' (global 'speed')
level = 1, const = 41, proto = 0, upval = 1, vars = 9, code = 215
GETTABLE v3 v3 1
 ; PC 41 CODE 01C280C7 OP 7 A 3 B 3 C 266 Bx 1802 sBx -129269
stack traceback:
	/storage/emulated/0/Pictures/LearningLua.lua:209 in function 'START'
	/storage/emulated/0/Pictures/LearningLua.lua:288 in main chunk
	[Java]: in ?
	at luaj.LuaValue.f(src:989)
	at luaj.LuaValue.c(src:2864)
	at luaj.LuaValue.i(src:2767)
	at luaj.LuaValue.w(src:1094)
	at luaj.LuaClosure.a(src:363)
	at luaj.LuaClosure.l(src:160)
	at luaj.LuaClosure.a(src:533)
	at luaj.LuaClosure.l(src:160)
	at android.ext.Script.d(src:6056)
	at android.ext.Script$ScriptThread.run(src:5785)

 

2 answers to this question

Recommended Posts

Posted

Using some temporary fix.

if menuBool == false then
    speed = gg.prompt
    (
      {'Animation Speed | default value = 1 | [1; 10]', 'Game Speed | default value = 1  [1; 10]', 'Playerobject Speed | default value = 1  [1; 10]', 'Jump hack', 'Player size | default value = 1 [1;10]'},
      {[1]='1', [2]='1', [3]='1', [5]='1'},
      {'number', 'number', 'number', 'checkbox', 'number'}
    )
  end
  
  if menuBool == true then
    speed = gg.prompt
    (
      {'Animation Speed | default value = 1 | [1; 10]', 'Game Speed | default value = 1  [1; 10]', 'Playerobject Speed | default value = 1  [1; 10]', 'Jump hack', 'Player size | default value = 1 [1;10]'},
      {[1]=characterAnimation[1]["value"], [2]=gameSpeedFull[1]["value"], [3]=characterObjectSpeed[1]["value"], [5]=characterObjectSize[1]["value"]},
      {'number', 'number', 'number', 'checkbox', 'number'}
    )
  end

It works fine using a the tables but im not sure if its good idea for use it. I do like to know how to fix the error of the original question.

 

Posted

Check if the second menu is nil and set it to the default value:

if secondmenu == nil then
speedvalue = speed[1]
else
speedvalue = defaultspeedvalue
end

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.