This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Left4Cake's profile picture

Each charater?

Started by Left4Cake, 05 October 2012 - 12:48 AM
Left4Cake #1
Posted 05 October 2012 - 02:48 AM
Is it possible to execute code in a loop for each character in a file?
Noodle #2
Posted 05 October 2012 - 02:54 AM
What exactly do you mean?
Execute code..
In a loop..
Each character in a file?
Lyqyd #3
Posted 05 October 2012 - 02:54 AM
for char in string.gmatch(file.readAll(), ".") do
MatazaNz #4
Posted 06 October 2012 - 04: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
Left4Cake #5
Posted 13 October 2012 - 02:14 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:

I mean to read a file and then execute code for each char in the file as opposed to each line of a file.
MatazaNz #6
Posted 13 October 2012 - 05: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.
GopherAtl #7
Posted 13 October 2012 - 05:25 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:

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.