Jump to content




[Lua][Question]Reading messages.


  • You cannot reply to this topic
8 replies to this topic

#1 exploder

  • Members
  • 69 posts
  • LocationLatvia

Posted 21 October 2012 - 07:18 PM

Hello computercraft community.

I am trying to make program that allows user to write messages,save them and show later, but I'm getting an error:startup:19: attemt to call a string (19 line is print("message "..message)

But I just can't get that right, I have red("I don't know if that's a verb because I don't know English that well.") the wiki and tutorials in this forums, but still I can't get it right.

And could you please show me how to make computer detect if there is message or not, because if there is no message then I want computer to say that to user(I tried fs.exists, but can't figure it out either.).


Spoiler

If you need more details, just ask.

Thank you.

#2 sjele

  • Members
  • 334 posts
  • LocationSomewhere on the planet called earth

Posted 21 October 2012 - 07:20 PM

On line 7 you are making print a string.
local print = file.readLine()

Spoiler


#3 exploder

  • Members
  • 69 posts
  • LocationLatvia

Posted 21 October 2012 - 08:08 PM

View Postsjele, on 21 October 2012 - 07:20 PM, said:

On line 7 you are making print a string.
local print = file.readLine()

Spoiler

Thank you, this worked, but could somebody help me again, because I have updated my code and I can't get os.pullEvent() to work this time.

The problem is when you write the message you can choose to continue or show message, but it doesn't seem to work because you can press any button on keyboard and it drops you back to menu, just this time the menu shows in terminal, what is the problem now?

Spoiler


#4 ChunLing

  • Members
  • 2,027 posts

Posted 21 October 2012 - 08:34 PM

"char" events only return the event "char" and a single parameter, the character. You're trying to use the second parameter, but it never exists and is always nil.

#5 exploder

  • Members
  • 69 posts
  • LocationLatvia

Posted 21 October 2012 - 10:57 PM

View PostChunLing, on 21 October 2012 - 08:34 PM, said:

"char ents only return the event "char" and a single parameter, the character. You're trying to use the second parameter, but it never exists and is always nil.

Thank you for replying, but could you explain this a bit in more detail because English is not really my native language.

Thank you.

#6 ChunLing

  • Members
  • 2,027 posts

Posted 21 October 2012 - 11:43 PM

From your code it looks like you already were able to fix this. Is there still a problem?
os.startTimer(0.5)
event, param1, param2 = os.pullEvent()
if event == "char" and param1 == "1" then access()
elseif event == "char" and param1 == "2" then shutdown()
elseif event == "char" and param1 == "3" then message()
elseif event == "char" and param1 == "4" then checkm()
end


#7 exploder

  • Members
  • 69 posts
  • LocationLatvia

Posted 22 October 2012 - 07:32 AM

View PostChunLing, on 21 October 2012 - 11:43 PM, said:

From your code it looks like you already were able to fix this. Is there still a problem?
os.startTimer(0.5)
event, param1, param2 = os.pullEvent()
if event == "char" and param1 == "1" then access()
elseif event == "char" and param1 == "2" then shutdown()
elseif event == "char" and param1 == "3" then message()
elseif event == "char" and param1 == "4" then checkm()
end

Yes, I tried that as well, but still can't get it working correct because it still gets me to main menu (just in terminal) by pressing any button.

#8 ChunLing

  • Members
  • 2,027 posts

Posted 22 October 2012 - 07:44 AM

Oh, right. You need to restrict your event pulls to chars, because key events arrive first. Use "os.pullEvent("char") " so that you don't pull key events, or if you want to use that timer event then use a repeat until loop that only exits when the timer fires.

#9 exploder

  • Members
  • 69 posts
  • LocationLatvia

Posted 22 October 2012 - 01:03 PM

View PostChunLing, on 22 October 2012 - 07:44 AM, said:

Oh, right. You need to restrict your event pulls to chars, because key events arrive first. Use "os.pullEvent("char") " so that you don't pull key events, or if you want to use that timer event then use a repeat until loop that only exits when the timer fires.

Thank you, now this works.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users