This simple prog. puts a letter on the screen using its Ascii code.
How could the prog. be used to ‘step’ through the alphabet using a ‘loop’ ?
I am struggling to understand the main 60 x a sec loop.
Forget to include code. Here it is.
function setup() Ascii="\\65" end function draw() font("TimesNewRomanPSMT") fontSize(512) fill(255) text((Ascii),WIDTH/2,HEIGHT/2) -- Using Ascii code end
Why not read up on how Codea works? Try the Codea ebook here.
Got as far as the balloon shooting code that I couldn’t get to work
Decided to have a go at learning by do it yourself. Got it to count but to step through the alphabet is another problem. Using the Ascii codes is one way. I had to search a bit to find out how to get Codea to recognise ASCII codes. To get Codea to step through the codes is something else.
Just thought the forum could help.
@Steep Here’s an ASCII chart I posted back in March 2013. This might give you some ideas.
You helped me with ‘Counting’’
I’ ll take a good look at your ASCII code prog. It seems to do a a lot with not too much code. Should keep me busy for a bit.
I’ll be back.
Got it from your Ascii prog Dave the key was ‘string.char’ . I also added your code for slowing the prog down. It’s the function delay(limit) that goes outside function draw. You used in your count prog. and I haven’t a clue how or why it works.
-- Alphabet with Dave's help function setup() dt=0 Ascii=65. -- A to start end function draw() background(65, 113, 40, 255) if Ascii<=90 then letter=string.char(Ascii) font("TimesNewRomanPSMT") fontSize(512) fill(255) if delay(1) then Ascii=Ascii+1 end end text((letter),WIDTH/2,HEIGHT/2) end function delay(limit) dt=dt+DeltaTime if dt>limit then dt=0 return true end return false end
My iPad now knows how to count and recite the alphabet.
Codea makes a new drawing every 1/60 of a second.
You only want the letter to change once per second.
So you need to measure time passing (DeltaTime is time since Codea last drew) and change the letter and restart the clock every time your counter reaches 1 (second).
You could also simply use the number of seconds since the program started
Thanks Ignatz but as a newby nothing is simple, in particular the built in 60/sec Codea loop, as I said earlier. Could you please put your code into my prog.
You guys seem to pluck ‘key words’ and expressions out of the air. Where do ‘string.char’ and ‘math.floor’ come from ?
Have a look at the reference link above, at the Lua section. You need to get an idea of the basic commands. When I started, I spent several weeks reading everything I could find on Lua. I’ve also written an ebook on Codea which covers things like tables, which are very important in Codea.
It’s like learning a language. To start with, you need to get used to the words and grammar. I have learned several programming languages, and in each case, it has taken me several weeks to get to where I can start writing simple programs, and in the meantime I feel like an idiot.
So don’t expect to understand everything straight away, or write a program immediately. Everyone finds it confusing at first, and the important thing is to read, and re-read, and practice, and learn from other people, books, etc.
Wrt your specific question, think of Codea as a metronome. Every 1/60 of a second, it runs the code in draw. So Codea is making a movie at 60 frames per second.
You only want to change the letter every second, so you need to put code in the draw function that checks if a second has passed. Your code needs to go in the draw function, because that is the only code that Codea runs automatically (except the setup function, which only runs once).
To do this, you need to know which Codea commands give you times. So what I would do is go look up the reference for those, and try them out to see what they do, then figure out how to use them in the code. So when you get stuck, go see if there’s a command that does what you want.
As I understand it Codea is some form of assembler that comes between Lua and Machine Code. I have coded with BBC Basic and struggled with its relationship to the Assembler. Machine code leaves me cold. Perhaps I am playing around at too high a language level. Never the less I play around with code for fun. Trial and error with the Alphabet got me here :-
-- Alphabet with Dave and 1ngnatz help function setup() -- Use Ignnatz expression. -- letter=string.char(math.floor(65+ElapsedTime)) -- but haven't a clue what it is doing. end function draw() background(65, 113, 40, 255) font("TimesNewRomanPSMT") fontSize(512) fill(255) letter=string.char(math.floor(65+ElapsedTime)) text((letter),WIDTH/2,HEIGHT/2) end
@Steep - please look at the Lua section of the reference link above. Each of those functions is clearly defined. Why should I need to explain them if they are already explained for you?
Surely you understand that you can’t write code if you haven’t made any effort to learn the language, by reading the explanation of the various functions.
Come on Ignatz I do my best struggling with an iPad in general and Wordpress , GitHub and Codea in particular. Please understand I was 55 when I first laid hands on a computer and Bill Gates and Steve Jobs were fighting for supremacy in the computer world. I have a hand coded web site that I ‘played’ around with on a D.I.Y basis:- http://homepage.ntlworld.com/g.steeper/
I do use the links you provide but it is so easy to get pulled in another direction.
Thank you for help that you have given me so far.
@Steep If you do a google search for Ascii table, depending on the table, you’ll see values from 0 to 255. Codea only displays the ASCII values from 32 thru 127. That’s special characters, the digits 0 thru 9, characters A thru Z, and a thru z. In the code you show above, 65 and ElapsedTime are being added together. So it starts at 65 and every second it increments the Ascii value you want to show. Once you exceed 127, you won’t see any more characters because Codea won’t display Ascii above 127. The best way to learn this stuff is to just play around with small programs. I never heard of Lua or Codea about 2.5 years ago, but I find it very easy to use. I started with small programs and tried different functions/commands just to see what they would do. There’s still a lot that Codea offers that I don’t understand, but that gives me stuff to learn. But then I programmed for 30+ years before I retired, so that helped.
@Steep - I’m not trying to be hard on you, but the function explanations are about as clear as you’re going to get. After that, it’s a matter of practice and learning from other people and their code. And I know it’s not easy, I’m retired myself, and I have struggled for days on end to solve small problems…
Dave and Ignatz - I’m with you all the way, Codea is as close as you can get to programming on the iPad. Truly, I enjoy the struggle and sense of achievement it brings.
The iPad in itself is a challenge. Ignatz’s link uses DropBox and opens up another line of exploration. I understand his frustration, when silly old b%#}^rs like me ask stupid questions.
By the way Ignatz your book is a gem. I hadn’t realised that Lua code could be run in the black box to the left of the Codea screen.
For the time being I’ve got what I wanted out of my look at the ‘alphabet’ and ‘counting’.
Please continue to keep an eye on me.
-- Ascii Codes with Dave and Ingnatz help. -- This prog. calls for Ascii Codes from 1 to 255 but only shows -- the symbols between 32 thru127 as Dave says in his post 1st.Feb. -- Ascii Code 169 does show up a symbol -- It stops with error beyond 255. -- function setup() is not required function draw() background(65, 113, 40, 255) font("TimesNewRomanPSMT") fontSize(512) fill(255) letter=string.char(math.floor(1+ElapsedTime)) text((letter),WIDTH/2,HEIGHT/2) fontSize(60) number=math.floor(1+ElapsedTime) text(("Ascii Code") ,300, 700) text ((number), 496,700) end
I will look at providing a stop/start. using touch screen.
When you use the STANDARD displayMode Codea automatically displays function buttons at the bottom of the viewer sidebar on the left side of the screen . I discovered that If you use the command ‘displayMode=FULLSCREEN’ before FunctionDraw() these buttons are displayed in the bottom LH corner of the full screen on your program. This among other features lets you pause the programme as required.
@Steep You’re going to discover a lot of what Codea does by experimenting with different commands and their options.