I am new to Codea, and coding in general. I have looked through many lua tutorials, so I know basic and simple things. I was told that creating a ‘text based’ game would be a good place to start, so I tried to make one. Turns out, I got practically nowhere. I don’t know how to make text output onto the screen, and I don’t know how to make the program receive input from the player. I really love the game ‘A Dark Room’ and I would really love to make a similar game to that. Any suggestions on where to start, or any specific tutorials to look at? Thank you so much!
@creardon1 I don’t know what the game “A Dark Room” looks like, but here is an example of inputting text and showing it’s output on the screen.
displayMode(FULLSCREEN) function setup() str = "" var="" bcolor= 0 x=300 y=500 w=400 h=50 l=x-w/2 --button left r=x+w/2 --right b=y-h/2 --bottom t=y+h/2 --top end function draw() background(30,30,0,255) strokeWidth(6) rectMode(CENTER) textMode(CENTER) fill(255) text("Tap input area, enter text then press return",x,550) if bcolor == 0 then fill(255, 0, 0, 255) else fill(128,0,0,255) end rect(x,y,w,h) -- input area fill(255) if keyboardBuffer() ~= nil then text(keyboardBuffer(),x,500) -- show data as it is keyed else showKeyboard() text(str,x,500) -- show data in input area end -- output area rect(x,HEIGHT-100,400,50) -- input area fill(255,0,0) text(var,x,HEIGHT-100) end function touched(t) if t.state==BEGAN then showKeyboard() end end function keyboard(key) -- move keyboardBuffer to str when return is pressed if key == RETURN then str = keyboardBuffer() var=str str="" hideKeyboard() bcolor = 0 end end
@dave1707 thanks a lot, that actually explains a ton. I was wondering if you knew what the print function does in codea? I know it prints text in a normal lua processor, but I found that this wasn’t the case in codea.
@creardon1 actually, print does just that – only it prints in the output area, not the graphical screen.
@Mark ok thanks.
Oh yes, and if you want to check out the game, here it is: http://adarkroom.doublespeakgames.com/