Jump to content




Each charater?


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

#1 Left4Cake

  • Members
  • 272 posts
  • LocationEarth

Posted 05 October 2012 - 01:48 AM

Is it possible to execute code in a loop for each character in a file?

#2 Noodle

  • Members
  • 989 posts
  • LocationSometime.

Posted 05 October 2012 - 01:54 AM

What exactly do you mean?
Execute code..
In a loop..
Each character in a file?

#3 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 05 October 2012 - 01:54 AM

for char in string.gmatch(file.readAll(), ".") do

#4 MatazaNz

  • Members
  • 42 posts
  • LocationNew Zealand

Posted 06 October 2012 - 03:04 AM

Do you mean to execute different functions with their own key press? If so, then it's perfectly possible.
You can do something like this:
local event,p1 = os.pullEvent()
if event == "char" and p1 == "<key>" then
  <function>
elseif <same as above with different key>
  <function>
end


#5 Left4Cake

  • Members
  • 272 posts
  • LocationEarth

Posted 13 October 2012 - 01:14 AM

View PostMatazaNz, on 06 October 2012 - 03:04 AM, said:

Do you mean to execute different functions with their own key press? If so, then it's perfectly possible.
You can do something like this:

I mean to read a file and then execute code for each char in the file as opposed to each line of a file.

#6 MatazaNz

  • Members
  • 42 posts
  • LocationNew Zealand

Posted 13 October 2012 - 04:22 AM

Sounds simple enough, but probably not too simple. I think you could have a bunch of local variables for each character, and link those characters to functions.

#7 GopherAtl

  • Members
  • 888 posts

Posted 13 October 2012 - 04:25 AM

View PostLeft4Cake, on 13 October 2012 - 01:14 AM, said:

View PostMatazaNz, on 06 October 2012 - 03:04 AM, said:

Do you mean to execute different functions with their own key press? If so, then it's perfectly possible.
You can do something like this:

I mean to read a file and then execute code for each char in the file as opposed to each line of a file.

yeeah... what lyqyd said does exactly that.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users