Jump to content




Strange PullEvent Quirk

computer

3 replies to this topic

#1 atomroflman

  • New Members
  • 1 posts

Posted 30 June 2016 - 08:48 PM

Hey guys,

I have a quite strange behavior in my code:
function showSelector(text, values, textFunc)
  local isSelected = false
  local cursor = 1
  local selectedValue = nil
  while not isSelected do
	local counter = 1
	clear()
print("Select " .. text .. ":")
	for i, v in pairs(values) do
	  local cursorText = "   "
	  if cursor == counter then
		cursorText = " > "
		selectedValue = v
	  end
	  counter = counter + 1
   if textFunc ~= nil then
	 print(cursorText..textFunc(v))
   else
		print(cursorText .. v)
   end
	end
glb = glb + 1
print("wait for key"..glb)
	local event, key = os.pullEvent("key")
print("key done"..glb)
	if key == keys.up then
	  if cursor > 1 then
		cursor = cursor - 1
	  end
	elseif key == keys.down then
	  if cursor < #values then
		cursor = cursor + 1
	  end
	elseif key == keys.enter then
	  isSelected = true
	end
  end
  clear()
  return selectedValue
end
When I try to execute it from one point in my program it works fine, from another it does not.
It just stops moving the cursor, as if the value of keys is not valid anymore. So I thought i've overwritten the keys table, but i didn't.

Find the full code here:

Spoiler

Edited by Bomb Bloke, 21 August 2016 - 12:09 AM.


#2 BrunoZockt

  • Members
  • 56 posts
  • LocationGermany

Posted 20 August 2016 - 04:25 PM

Hey,
I'd like to help you but I don't understand what your problem is.
Are you getting an Error? If yes then post it please.
Or doesn't the program do what you want? If that's the case please describe what you want it to do and what it actually does.
If you don't need help anymore, edit your post and write that you don't need help anymore or add a "[solved]" to your title.

Bruno

#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 20 August 2016 - 06:22 PM

He described his problem adequetly in the post and comments. I can't address it because I am on mobile, but the information is there.

#4 BrunoZockt

  • Members
  • 56 posts
  • LocationGermany

Posted 20 August 2016 - 08:42 PM

View PostKingofGamesYami, on 20 August 2016 - 06:22 PM, said:

He described his problem adequetly in the post and comments. I can't address it because I am on mobile, but the information is there.
Oh, sorry!
I didn't see the text between the codes yet. It helps a bit, but however I don't know what his code should do.
I try to read myself through the code when I know what I am looking for and what it should do because otherwise it's really hard, but for now, maybe it's because of my bad english, I don't know what should happen.
So please tell me what should happen and I will work on it.

Bruno





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users