```
if leveltimer ==1 and level==1 then
wave={AlienA(col1,row3,a,1),AlienA(col1, row3*1.1,a,1), AlienA(col1, row3*1.2,a,1), AlienA(col1,row3*1.3,a,1), AlienA(col1,row3*1.4,a,1), RockA(col4,row3), RockB(col2,row3*1.2)}
end
if leveltimer ==400 and level==1 then
table.insert(wave, AlienA(col1,row3,a,1),AlienA(col1, row3*1.1,a,1), AlienA(col1, row3*1.2,a,1), AlienA(col1,row3*1.3,a,1), AlienA(col1,row3*1.4,a,1), RockA(col2,row3), RockB(col4,row3*1.2) )
end
```

Which is filling the table 'wave' with the first wave of alIens. Then when timer hits 400 it inserts new aliens into the table. The first part works well but I get errors one the next part.

The reason I doing a timer based insertion is my game involves time travel so you can jump back in time to fix something.

Thanks

]]>```
function setup()
A = 0
end
function draw()
A = A + 0.0125
B = A // 1
C = math.floor(A)
fill(255); textMode(CORNER)
text(type(A).." = "..A,150,700)
text(type(B).." = "..B,150,680)
text(type(C).." = "..C,150,660)
end
```

A obviously outputs as a float, whilst B is displayed as "n.0" and C is just displayed as "n".

I'm not bothered about the output - I know that can be controlled via string.format(), but I was curious as to whether B is actually a true integer.

Turns out in this example you could pass B as a parameter to a function like image.get() (which will fail if you pass A ) or is it due to the fact that B has no fractional part and can therefore be internally converted into an integer.

So it looks like using the new integer divider operator (//) might work as a quick way to floor a value - the question is, is it a faster / cleaner way than using math.floor (or a local reference to math.floor)?

]]>I have 2 questions, where do I get the updated runtime, and how do I update my Xcode addons to match? I need to fix @Zoyt 's Sharing addon and In-App purchase addon.

Thanks, ~Patrick

EDIT: I tried following these instructions to update the runtime, and then these to update the addons, but when I started replacing CodeavViewController with StandaloneCodeaViewController I get numerous errors and am unsure if everywhere that says codeaviewcontroller needs replacing or just some of them. I needed to restore with time machine to get the game back to a working state. How do I update them properly?

]]>`\u{}`

escape code that comes with Lua 5.3, this problem is now quite easy to solve. I wrote a quick portabilizer, that turns the contents of your clipboard, or text that you input, into Lua 5.3 compliant utf escape codes, for easier code sharing. Update: optional text input.
```
--# Main
-- Emoji portabilizer v1.1. by Yojimbo2000. Requires Lua 5.3
-- how to use: copy to the clipboard a bunch of emoji or other non-standard characters that you want to make portable. Alternatively, you can enter text into the InputString box when you run the app.
-- run this program. It will return to the clipboard the Lua 5.3 compliant \u{xxx} utf8 escape codes for the characters that you copied or entered
-- There is also an optional verbose output. It places "character = \u{xxx}, " in the clipboard
-- paste the clipboard back into your code.
-- Emoji and other non-standard characters will now be portable (ie not get corrupted on gist raw pages, pastebin, Codea Talk etc )
function setup()
parameter.text("InputString", pasteboard.text, function()
verbose, concise = "", ""
for _,code in utf8.codes(InputString) do --iterator returns utf code as decimal
local hex=string.format("%x", code) --convert to hex
local escape ="\\u{"..hex.."}" --add (escaped) utf8 escape code
local char=utf8.char(code) --grab the character (for verbose out)
verbose = verbose..char.." = "..escape..", " --concatenate
concise = concise..escape
end
output.clear()
print ("concise output: "..concise)
print ("verbose output: "..verbose)
pasteboard.copy(concise) --return to clipboard
print ("Concise output copied to clipboard")
end)
parameter.action("Copy verbose output", function() pasteboard.copy(verbose) end) --optional output
end
```

I'm trying to use the new UTF-8 libraries that ship with Lua 5.3. The Lua reference manual says this about UTF-8:

The UTF-8 encoding of a Unicode character can be inserted in a literal string with the escape sequence \u{XXX} (note the mandatory enclosing brackets), where XXX is a sequence of one or more hexadecimal digits representing the character code point.

I'm trying to use these with emoji. ie, take "MONKEY FACE" UTF-8 is F0 9F 90 B5, Unicode is U+1F435 (U+D83D U+DC35)

But when I try `"\u{F09F90B5}"`

, Codea gives me a "UTF-8 value too large" error.

I don't really know what I'm doing with UTF-8, can anyone help?

]]>Box2D is a rigid-body system, so one of the things I'd like to work on is "fooling" the user into thinking that the bodies are in fact flexible, using animation. That's the (tenuous?) link to the gamejam theme of "responsiveness" anyway, how our sense of how something feels can be affected by the way it is animated.

I thought I'd start with an attempt to squash and stretch a ball, depending on the normal of its collision, so that it feels like it's made out of rubber. It's harder than it sounds.

Here's my first, not terribly convincing attempt:

I'll share the code later.

I feel like I've already broken my own rules though, starting off with an animation, rather than actual gameplay....

]]>```
--# Main
displayMode(STANDARD)
function setup()
local bounds = vec2(600, 300)
logoImg = nil
fontSize(96)
local generate = function()
logoImg = genLogo(bounds)
end
parameter.text("NAME", "Title Here", generate)
parameter.integer("FONT", 1, 9, 1, generate)
parameter.action("Regenerate", generate)
end
function genLogo(bounds)
local pal = {
palettes.winter,
}
local fonts = {
("AmericanTypewriter-Bold"),
("ArialRoundedMTBold"),
("Futura-Medium"),
("Futura-CondensedExtraBold"),
("Courier-Bold"),
("HelveticaNeue-Light"),
("Noteworthy-Bold"),
("SourceSansPro-Bold"),
("Vegur-Bold"),
}
local pidx = 1
local fidx = FONT or 1
local img = image(bounds:unpack())
font(fonts[fidx])
setContext(img)
renderString(NAME, bounds, pal[pidx])
setContext()
return img
end
function draw()
-- This sets a dark background color
background(85, 85, 108, 255)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
sprite(logoImg, WIDTH/2, HEIGHT/2)
end
function renderString(str, bounds, scheme)
pushStyle()
textAlign(CENTER)
local w,h = textSize(str)
local xoffset = bounds.x/2 - w/3
local ycenter = bounds.y/2
str:gsub(".", function(c)
w = textSize(c)
local pos = vec2(xoffset, ycenter)
pushMatrix()
translate(pos:unpack())
--translate(-pos:unpack())
blendMode(NORMAL)
fill(scheme[2])
text(c, 0, 0)
popMatrix()
xoffset = xoffset + w
end)
popStyle()
end
--# Palettes
palettes = {}
palettes.winter = {
color(241, 243, 243, 255),
color(169, 219, 223, 255),
color(59, 130, 169, 255),
color(38, 80, 83, 255),
}
```

]]>My top score is 1915.

]]>Will the Codea implementation of LuaSocket be changed at all from the normal library? Just wondering, and I assume not.

In most multiplayer games, you can scan for local games. Is there a way to do this, to check for IP's on the local network hosting games and then connect to the sockets from there with any of the LuaSocket libraries?

Can you send anything other than strings over the sockets? I don't really care, but if it is just strings then I see a lot of loadstring()() in my future.

Will TCP be the only implementation of LuaSocket, or will there be any others such as FTP, etc?

Thanks for taking the time to read my stupid questions if anyone knows, and answering this brings me one step closer to building a simple multiplayer library for you all! Thanks!

-TheSolderKing

]]>**Squash and Stretch** code / thread

Here's the voting form!

https://www.surveymonkey.com/s/D2ZK3HF

The password is `cookoff`

(all lower-case)

All Codea Talk forum members can vote for the entry that they feel best meets the 3 criteria below, as well as an overall winner.

Voters should play all of the entries.

You cannot vote for your own entry.

Think user experience, controls, feedback (visual and auditory), rewards. Think touch and tilt. Think sockets.

This isn't just about having good controls, but also all of the feedback (including animations and sound) by which we let the player know an action is completed, the rewards they get when it is completed successfully. All the things we mean when we talk about "the feel" of a game. This sense of how a game feels is often left to the end of game development (or worse, neglected all together), but the beauty of Codea is that we have that PLAY button continuously available in the bottom corner: unlike the desktop-bound developer, we can continuously test and tweak "the feel" of our games from the very beginning.

The winning entry will....

be a fun and replayable game around the theme of "responsiveness"; ie with special attention paid to the user experience, with tight controls and feedback, and some kind of goal and reward structure, even if it's just staying alive or racking up a high score

have concise and readable code, with a reasonable amount of documentation in the comments. There's no line limit, but try to avoid code repetition

"show off" some aspect of Codea, whether it's Box2D, shaders, 3D graphics, sound, the newly announced sockets (online multiplayer) or iOS technologies like gyroscopes or system voices

entries should largely be an original work created for the competition (though inevitably you will reuse bits of other code you have lying around)

entries can be individual or group efforts, but no more than one per person

you will retain all rights over your entry

Further suggestions welcome on all of the above!

]]>It has a track editor shown at the start of the video below, allowing you to push the track into a shape of your choice, then you can race on it (this technique could be used to create a sculpting app).

I still need to provide the ability to save and load custom tracks, and scoring, and maybe things on the track to collect or avoid.

But the app is all about responsiveness.

]]>The basic idea is this: You can version/source control your Codea projects by pushing the code to remote repositories on hosting sites, such as Github, Bitbucket, Gitlab, and so for. There are 2 parts to the system: a Codea app that you would run in your Codea workspace on iPad, and a web service that runs on my server at https://codea-scm.aws.mapote.com , which does the communications with repo hosting sites, and basically acts as a proxy for your source control actions.

The web site has install instructions and more detailed info, which is recommended to take a look at: https://codea-scm.aws.mapote.com/

But if you are eager to get started, without reading any further, here's the bootstrap installer for you:

```
--# Main
-- codea-scm bootstrap installer
function setup()
displayMode(STANDARD)
print("Installing codea-scm ...")
http.request("https://codea-scm.aws.mapote.com/install",
function (data, status, headers)
assert(loadstring(data))()
print("Installation complete. SUCCESS!")
print("Launch the project again to start using codea-scm.")
tween.delay(2.0, close)
end,
function (err)
print("PROBLEM downloading: " .. err)
end)
end
function draw()
background(37, 38, 50, 255)
end
```

Possible uses:

versioning and backups: We are using true source control system, so yep we get the versioning from it. Backups are taken care off somewhat indirectly - by using remote repositories hosted at GitHub and other well known sites, (Presumably, they look after their storage systems and back them up regularly :) )

coding on both iPad and your laptop/desktop: Some types of changes are just much easier to do on a computer. Vim, full keyboard, etc.. You can do that, then commit and push your changes to the repository, then pull them to the iPad - to continue working there.

code sharing: The nice thing about repo hosting sites - such as GitHub and Bitbucket - they already have the infrastructure built around users and projects, and the logic and the UI all figured out. By hosting your repositories on one of those sites, you can leverage their access control mechanisms to share your Codea projects with just friends or everybody (or no one, if you don't want to).

Limitations:

Right now only

**git**is supported, although i tried to keep the web service and the app generic enough, so that other scm's can be added in the future, if needed/wanted. For instance, Mercurial (Hg) and Subversion should not be hard to add support for.You are limited to "Diff", "Push", and "Pull" operations. Anything more complex, you'd still need to do on your laptop/desktop. (Which is probably better kept that way anyway)

Only your source tabs are pushed/pulled. Assets, such as sprites, are not versioned. I still need to figure out a way to handle those.

Codea-SCM works on Codea 1.5.5 and Codea 2.0. However, with 2.0, there is a caveat to be aware of - related to **http.request**. It seems that in Codea 2.0, if you restart the project, http.request stops working (all requests just hang). Since Codea-SCM uses http.request quite a bit, the workaround is: don't restart the project, simply close it, and then press the "play" button again. Then all should be good.

--# Main
function setup()
displayMode(FULLSCREEN)
st = SmokeTest()
end
function draw()
st:draw()
end
function touched(touch)
st:touched(touch)
end
--# Smoke
Smoke = class()
function Smoke:init(killDistance)
self.particles = {}
self.kill = killDistance
end
function Smoke:addParticles(position, direction)
-- 1 = color, 2 = direction, 3 = start position, 4 = current positiom
local pos = table.maxn(self.particles) +1
self.particles[pos] = {}
self.particles[pos][1] = vec4(255,145,0,255)
self.particles[pos][2] = direction
self.particles[pos][3] = position
self.particles[pos][4] = position
end
function Smoke:draw()
for p = 1, table.maxn(self.particles) do
if self.particles[p][4]:dist(self.particles[p][3]) < self.kill then
fill(255, 115, 0, 255)
ellipse(self.particles[p][4].x, self.particles[p][4].y, WIDTH/10)
self.particles[p][4] = self.particles[p][4] + self.particles[p][2]
else
print(self.particles[p][4]:dist(self.particles[p][3]))
print(table.maxn(self.particles).."s2")
table.remove(self.particles, p)
print(table.maxn(self.particles).."s1")
end
end
end
function Smoke:touched(touch)
-- Codea does not automatically call this method
end
--# SmokeTest
--For testing and demonstration of smoke class. Remove in finished project!
SmokeTest = class()
function SmokeTest:init()
self.delay = 1
self.smoke = Smoke(300)
end
function SmokeTest:draw()
background(0, 149, 255, 255)
self.smoke:draw()
end
function SmokeTest:touched(touch)
if touch.state == BEGAN or MOVING then
if self.delay == 5 then
self.delay = 1
self.smoke:addParticles(vec2(CurrentTouch.x, CurrentTouch.y), vec2(2,0))
else
self.delay = self.delay + 1
end
end
end

]]>Gameplay : you must stay alive as long as you can

Joystick class made by Dave1707

Background class made by West

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)
function setup()
http.request("http://pastebin.com/raw.php?i=n6nMmH68",
function(d) loadstring(d)() setup() end,
function(e) print(e) end
)
end

]]>Code link: https://gist.github.com/JakAttak/44c541318700bbe3c687

]]>- People popcorn. Bounce the people into then rescue ships using exploding crates. Extra points for saving the queen. Complete with a finite state machine and high scores and sounds. Not entirely happy with the gameplay as directing people seems a bit random.

- Space invaderish. Shoot the incoming aliens. Flick to create rockets, tap for smartbombs (missile commandesque). Aliens get progressively faster and bonus ones appear at random (shields, extra smartbomb and a freeze which temporarily stops your rockets overheating). Still need to implement high score, finite state machine and sounds. Would also like to work on waves of aliens to get a feeling of progression, rather than its current survival mode.

Neither have much to do with "Responsiveness" :-/

]]>https://gist.github.com/Jaybob/aed50b388e173257e9a5

More features and a better UI coming soon!

Enjoy!

]]>

I'm using a for i=1,50 type loop which works well. The only thing is when it's finished I want to change a variable at that point.

Writing an else doesn't work.

Writing a test of if i==50 doesn't work as for some reason it cuts the i loop short

Any ideas?

Thank

]]>```
-- 2D Platformer
supportedOrientations(CurrentOrientation)
-- Use this function to perform your initial setup
function setup()
--Character setup
player = Character()
--Level setup
stage = Level()
end
function draw()
background(0, 92, 255, 255)
strokeWidth(5)
camera(mainCharacter.x-WIDTH/2, mainCharacter.y-HEIGHT/3, 10, mainCharacter.x-WIDTH/2, mainCharacter.y-HEIGHT/3, 1)
player:draw()
stage:draw()
end
function touched(touch)
player:touched(touch)
end
function collide(contact)
player:collide(contact)
end
Character = class()
function Character:init(x)
-- you can accept and set parameters here
spriteMode(CENTER)
characterSize = 75
characterSpeed = 6
characterMaxSpeed = 250
mainCharacter = physics.body(CIRCLE, characterSize/1.5)
mainCharacter.gravityScale = 2
mainCharacter.restitution = .2
mainCharacter.x = WIDTH/2
mainCharacter.y = HEIGHT/2
characterGrounded = 0 -- 0 is false, 1 is true
mainCharacter.friction = .2
mainCharacter.fixedRotation = true
end
function Character:draw()
-- Codea does not automatically call this method
sprite("Platformer Art:Guy Standing", mainCharacter.x, mainCharacter.y, characterSize)
--print(mainCharacter.linearVelocity.x)
if mainCharacter.linearVelocity.x < characterMaxSpeed and mainCharacter.linearVelocity.x > -characterMaxSpeed then
mainCharacter:applyForce(vec2(Gravity.x*300, 0))
end
-- mainCharacter.x = mainCharacter.x + Gravity.x * characterSpeed
end
function Character:touched(touch)
-- Codea does not automatically call this method
end
function Character:collide(contact)
if contact.state == BEGAN then
print( contact.bodyA.info)
if contact.bodyA ~= nil then
if contact.bodyA.info == "ground" then
characterGrounded = 1
print("hit")
end
end
end
end
function Character:touched(touch)
if touch.state == BEGAN then
if characterGrounded == 1 then
mainCharacter:applyForce(vec2(0, 5000))
characterGrounded=0
print("jump")
end
end
end
Level = class()
function Level:init()
-- you can accept and set parameters here
rectMode(CENTER)
--0: empty
--1:ground
--2: wall
--3: cloud
--4: levelEnd
--5: coin
levelLayout =
{
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,4},
{1,0,0,0,0,0,0,0,5,1},
{2,0,0,0,3,0,0,5,1,2},
{2,0,0,0,0,0,5,1,2,2},
{2,0,0,0,0,5,1,2,2,2},
{2,0,0,0,0,1,2,2,2,2},
{1,1,1,1,1,1,1,1,1,1}
}
for i, row in ipairs(levelLayout) do
for j, block in pairs(row) do
if levelLayout[i][j] == 1 or levelLayout[i][j] == 2 then
--print(levelLayout[i][j])
rectWidth = 100
rectHeight = 100
physicsRect = physics.body(POLYGON,
vec2(-rectWidth/2, -rectHeight/2), --bottom left
vec2(-rectWidth/2, rectHeight/2), --top left
vec2(rectWidth/2, rectHeight/2), --top right
vec2(rectWidth/2, -rectHeight/2) --bottom right
)
physicsRect.gravityScale = 0
physicsRect.restitution = 0.1
physicsRect.x = j*100
physicsRect.y = HEIGHT-(100*i)
physicsRect.type = STATIC
physicsRect.friction = .2
if levelLayout[i][j] == 1 then
physicsRect.info = "ground"
end
if levelLayout[i][j] == 2 then
physicsRect.info = "wall"
end
end
if levelLayout[i][j] == 4 then
starSize = 100
star = physics.body(CIRCLE, starSize/2)
star.gravityScale = 5
star.restitution = .2
star.x = j*100
star.y = HEIGHT-(100*1)
star.info = "star"
end
end
end
end
function Level:draw()
-- Codea does not automatically call this method
for i, row in ipairs(levelLayout) do
for j, block in pairs(row) do
if levelLayout[i][j] == 1 then
sprite("Platformer Art:Block Grass", j*100, HEIGHT-(100*i), 100, 100)
end
if levelLayout[i][j] == 2 then
sprite("Platformer Art:Block Brick", j*100, HEIGHT-(100*i), 100, 100)
end
if levelLayout[i][j] == 3 then
sprite("Platformer Art:Cloud 2", j*100, HEIGHT-(100*i), 200, 100)
end
if levelLayout[i][j] == 4 then
sprite("Small World:Glow", j*100, HEIGHT-(100*i), 100, 100)
end
if levelLayout[i][j] == 5 then
sprite("Platformer Art:Coin", j*100, HEIGHT-(100*i), 30, 30)
end
end
end
end
function Level:touched(touch)
-- Codea does not automatically call this method
end
```

]]>Example output

You can customise colour palette and font.

```
--# Main
-- Logotron
displayMode(STANDARD)
function setup()
local bounds = vec2(600, 300)
logoImg = nil
fontSize(96)
local generate = function()
logoImg = genLogo(bounds)
end
parameter.text("NAME", "Title Here", generate)
parameter.integer("PALETTE", 1, 7, 1, generate)
parameter.integer("FONT", 1, 9, 1, generate)
parameter.action("Regenerate", generate)
end
function genLogo(bounds)
local pal = {
palettes.winter,
palettes.earthy,
palettes.fiery,
palettes.space,
palettes.darkness,
palettes.dusty,
palettes.sky,
}
local fonts = {
("AmericanTypewriter-Bold"),
("ArialRoundedMTBold"),
("Futura-Medium"),
("Futura-CondensedExtraBold"),
("Courier-Bold"),
("HelveticaNeue-Light"),
("Noteworthy-Bold"),
("SourceSansPro-Bold"),
("Vegur-Bold"),
}
local pidx = PALETTE or 1
local fidx = FONT or 1
local img = image(bounds:unpack())
font(fonts[fidx])
setContext(img)
renderString(NAME, bounds, pal[pidx])
setContext()
return img
end
function draw()
-- This sets a dark background color
background(85, 85, 108, 255)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
sprite(logoImg, WIDTH/2, HEIGHT/2)
end
function renderCircles(count, origin, bounds)
local ls = bounds.x // 5
local us = bounds.x // 2
for i = 1, count do
local rad = math.random(ls, us)
local pos = vec2(math.random(math.floor(bounds.x)),
math.random(math.floor(bounds.y)))
pos = pos + origin
ellipse(pos.x, pos.y, rad)
end
end
function renderString(str, bounds, scheme)
pushStyle()
textAlign(CENTER)
local w,h = textSize(str)
local xoffset = bounds.x/2 - w/3
local ycenter = bounds.y/2
str:gsub(".", function(c)
w = textSize(c)
if c == " " then
w = w * 1.35
else
w = w * 0.85
end
local s = (math.random() * 0.25) + 0.75
local pos = vec2(xoffset, ycenter + math.random(-5, 5))
pushMatrix()
translate(pos:unpack())
scale(s)
rotate(math.random() * 10 - 5)
translate(-pos:unpack())
blendMode(NORMAL)
fill(scheme[4])
text(c, 3, -5)
fill(scheme[3])
text(c, -2, 2)
fill(scheme[1])
text(c, 0, 0)
blendMode(MULTIPLY)
fill(scheme[2])
renderCircles(20, -vec2(w, h)/2, vec2(w, h))
popMatrix()
xoffset = xoffset + w * s
end)
popStyle()
end
--# Palettes
palettes = {}
palettes.winter = {
color(241, 243, 243, 255),
color(169, 219, 223, 255),
color(59, 130, 169, 255),
color(38, 80, 83, 255),
}
palettes.earthy = {
color(83, 218, 43, 255),
color(28, 160, 25, 255),
color(155, 79, 50, 255),
color(63, 40, 40, 255),
}
palettes.fiery = {
color(251, 92, 0, 255),
color(222, 182, 130, 255),
color(116, 43, 31, 255),
color(71, 30, 30, 255),
}
palettes.space = {
color(52, 41, 103, 255),
color(203, 200, 223, 255),
color(148, 139, 205, 255),
color(156, 54, 201, 255),
}
palettes.darkness = {
color(0, 0, 0, 255),
color(42, 85, 72, 255),
color(58, 101, 129, 255),
color(163, 183, 192, 255),
}
palettes.dusty = {
color(255, 255, 255, 255),
color(222, 201, 175, 255),
color(249, 194, 13, 255),
color(57, 69, 30, 255),
}
palettes.sky = {
color(93, 163, 230, 255),
color(216, 222, 230, 255),
color(154, 192, 223, 255),
color(30, 45, 118, 255),
}
```

]]>Space Flight!

**The Objective**

Playing as an astronaut, your objective is to get as many charges as possible, while avoiding the teleporting ESD's (ElectroStatic Discharge) before succumbing to the strength of the black hole. As you gather more charge, the blackhole suction will increase.

**Video**

**New Hardcore Mode Video**

**Current Features**

Achievements!

Game Recording!

Easter Eggs!

Dynamic Background!

**Code**

```
supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)
function setup()
http.request("http://pastebin.com/raw.php?i=69UDn9mb",
function(d) loadstring(d)() setup() end,
function(e) print(e) end
)
end
```

**How it relates to the theme**

'Space Flight!' Is all about adapting and RESPONDING to changing charge locations while dealing with the speed of the character.

**Leave any feedback below :)**

```
function readTest(file)
print("------------------------ ")
print("read from "..file)
io.input(io.open(file,"r"))
local li
for i in io.lines() do print(i) end
-- no close needed: done by io.lines()
print("---- read done ----")
end
```

with io functions and io.lines()

but now we have readtext but how can i use it to read word by word and line by line and save words by example in tab

@simeon write new goto statement ( is it BASIC GOTO ? )

thanks

]]>Just downloaded the free Meshlab for iOS onto my Pad2. Looks great - three example models in PLY and a similar visualisation to the desktop. It might be me, but, I can't find out how to download my own models. Have any of you installed this? I also have downloaded the app for Android but that won't run due to a failure of a supporting package.

I'll be contacting the authors but wondered if anyone here had tried it.

Bri_G

:-/

]]>https://coolcodea.wordpress.com/2015/03/12/3d-walk-through-castle/

This gives you an idea of how it's starting to look

Comments and suggestions welcome.

]]>

--# addRect
addRect = class()
function addRect:init(x,y,endX,endY)
-- you can accept and set parameters here
local w,h = endX-x,endY-y
self.body = physics.body(POLYGON,vec2(w/2,h/2),vec2(w/2,-h/2),vec2(-w/2,-h/2),vec2(-w/2,h/2))
self.body.x = (x + endX)/2
self.body.y = (y + endY)/2
self.m = mesh()
self.m.vertices = triangulate(self.body.points)
self.m:setColors(255,255,255)
self.body.fixedRotation = false
self.body.friction = 0.2
self.body.restitution = 0.0
self.body.angle = 0
end
function addRect:draw()
-- Codea does not automatically call this method
pushMatrix()
translate(self.body.x,self.body.y)
rotate(self.body.angle)
self.m:draw()
popMatrix()
end
function addRect:touched(touch)
-- Codea does not automatically call this method
end
--# Main
-- Creations testing
-- Use this function to perform your initial setup
function setup()
print("Hello World!")
objects = {}
local a = generateWorld()
m = mesh()
m.vertices = triangulate(a)
m:setColors(0,255,0)
ground = physics.body(CHAIN,loop,unpack(a))
touches = {}
tId = nil
initPos = nil
noSmooth()
frame = 1
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
noStroke()
fill(255)
-- Do your drawing here
m:draw()
if tId then
if touches[tId].state==ENDED then
objects[#objects+1] = addRect(initPos.x,initPos.y,touches[tId].x,touches[tId].y)
tId = nil
initPos = nil
else
rect(initPos.x,initPos.y,touches[tId].x-initPos.x,touches[tId].y-initPos.y)
end
end
for i,v in pairs(objects) do
v:draw()
end
text(math.floor(1/DeltaTime),WIDTH-10,HEIGHT-10)
frame = frame + 1
end
function generateWorld()
local verts = {}
local control = math.random(0,100)
for x=0,WIDTH, 5 do
verts[#verts+1] = vec2(x,noise(x/100,control)*100+100)
end
verts[#verts+1] = vec2(WIDTH,verts[#verts].y)
verts[#verts+1] = vec2(WIDTH,0)
verts[#verts+1] = vec2(0,0)
return verts
end
function touched(t)
if not initPos and t.state==BEGAN then
initPos = vec2(t.x,t.y)
tId = t.id
end
touches[t.id] = t
end

Just a quick little example of using physics bodies, nothing too complicated. Sorry no documentation-I really should get around to that. Psst-set friction to 100 and fixedRotation to true to have some fun :)

]]>So in my new game I'm using hit detection that works well.

In the alien class there here's the hit detect which works

```
for a,b in ipairs(bullets) do
if b.y >= self.y-scalerY*7.5 and b.y <= self.y+scalerY*7.5 and b.x >= self.x-scalerX*7 and b.x <= self.x+scalerX*7 then
table.insert(hits, Hit(b.x,self.y-scalerY*6) )
table.remove(bullets,a)
self.shot=true
sound(SOUND_EXPLODE, 61, 0.5)
end
end
```

It scans the table bullets and sees if any hits the alien comparing the alien x pos (self.x) with bullet positon (b.x)

That works great. You'll also see the line

```
table.insert (hits...
```

That line inserts a hit class (a hit animation) at the point of impact on the alien. Currently for some reason it's not picking it up properly and is half a screen away despite being accurately used to detect the hit.

What I want to do is log the position of the bullet where it hit the alien object and attach the hit class to that x position. I've tried self.x and all it does it attach to the center of the alien and not the actual pixel position it hit the alien within that hit criteria of

```
b.x >= self.x-scalerX*7 and b.x <= self.x+scalerX*7
```

Your wisdom as ever is greatly appreciate!

Thanks, The major

]]>So here is my code :) ::

```
function touched(touch)
if CurrentTouch.x > 0 and CurrentTouch.x < 768 and CurrentTouch.y > 380 and CurrentTouch.y < 880 then
showKeyboard()
elseif
CurrentTouch.x > 259 and CurrentTouch.x < 509 and CurrentTouch.y > 150 and CurrentTouch.y < 250 then
speakWords()
elseif
CurrentTouch.x > 700 and CurrentTouch.x < 780 and CurrentTouch.y > 874 and CurrentTouch.y < 946 then
words = ""
elseif
CurrentTouch.x > 610 and CurrentTouch.x < 690 and CurrentTouch.y > 870 and CurrentTouch.y < 950 then
words = pasteboard.text
end
end
```

It would be nice if somebody of you could help me with my problem :) that would be very nice Thank you

]]>Has anyone else noticed this?

]]>

--# Main
-- ShapeLibrary --
function setup()
parameter.integer("CurrentShape",1,5,1)
parameter.number("camDist",0,2000,1000)
parameter.number("Y",-1000,1000,200)
parameter.number("ang",-360,360,-70)
shapes = {
Shape:circleNofill(200,30,4),
Shape:circle(200,30),
Shape:sphere(200,50),
Shape:cube(400,400,400),
Shape:rCube(400,400,400,100,20)}
for k,v in pairs(shapes) do
for j = 1,#v.vertices do
v:color(j,math.random(50,255),math.random(50,255),math.random(50,255))
end
end
end
function draw()
background(24, 24, 24, 255)
x = math.cos(math.rad(ang))*- camDist
z = math.sin(math.rad(ang))*- camDist
perspective()
camera(x,Y,z,0,0,0)
shapes[CurrentShape]:draw()
end
--# Shape
Shape = class()
function Shape:sphere(r,n,t) -- radius,detail,translate
local t = t or vec3(0,0,0)
local p = {}
local vi = 180/n
local hi = 360/n
for angV = -90,90-vi,vi do
local h1 = math.cos(math.rad(angV)) * r
local h2 = math.cos(math.rad(angV+vi)) * r
local y1 = math.sin(math.rad(angV)) * r
local y2 = math.sin(math.rad(angV+vi)) * r
for angH = -180,180-hi,hi do
local p1 = vec3(math.cos(math.rad(angH))*h1,y1,math.sin(math.rad(angH))*h1)
local p2 = vec3(math.cos(math.rad(angH+hi))*h1,y1,math.sin(math.rad(angH+hi))*h1)
local p3 = vec3(math.cos(math.rad(angH))*h2,y2,math.sin(math.rad(angH))*h2)
local p4 = vec3(math.cos(math.rad(angH+hi))*h2,y2,math.sin(math.rad(angH+hi))*h2)
p[#p+1] = p1 + t
p[#p+1] = p2 + t
p[#p+1] = p4 + t
----------------
p[#p+1] = p1 + t
p[#p+1] = p3 + t
p[#p+1] = p4 + t
end
end
local m = mesh()
m.vertices = p
m:setColors(255,255,255,255)
return m
end
function Shape:cube(w,h,z,t) -- width,height,depth,translate
local w,h,z,t = w/2,h/2,z/2,t or vec3(0,0,0)
local A,B,C,D,a,b,c,d =
vec3(-w, h, z)+t,vec3( w, h, z)+t,vec3(-w,-h, z)+t,vec3( w,-h, z)+t,
vec3(-w, h,-z)+t,vec3( w, h,-z)+t,vec3(-w,-h,-z)+t,vec3( w,-h,-z)+t
local m = mesh()
m.vertices = {A,a,b,A,B,b,c,C,D,c,d,D,c,a,A,c,C,A,D,d,b,D,B,b,c,d,b,c,a,b,A,B,D,A,C,D}
m:setColors(255,255,255,255)
return m
end
function Shape:circle(r,n,t) -- radius,detail,tanslate
local p = {}
local t = t or vec3(0,0,0)
local j = 360/n
for i = 0,360,j do
p[#p+1] = t
p[#p+1] = vec3(math.sin(math.rad(i))*(r),math.cos(math.rad(i))*(r),0)+t
p[#p+1] = vec3(math.sin(math.rad(i+j))*(r),math.cos(math.rad(i+j))*(r),0)+t
end
local m = mesh()
m.vertices = p
m:setColors(255,255,255,255)
return m
end
function Shape:circleNofill(r,n,w,t) -- radius,detail,width,translate
local p = {}
local t = t or vec3(0,0,0)
local j = 360/n
for i = 0,360,j do
p1 = vec3(math.sin(math.rad(i))*(r-w),math.cos(math.rad(i))*(r-w),0)
p2 = vec3(math.sin(math.rad(i))*(r),math.cos(math.rad(i))*(r),0)
p3 = vec3(math.sin(math.rad(i+j))*(r-w),math.cos(math.rad(i+j))*(r-w),0)
p4 = vec3(math.sin(math.rad(i+j))*(r),math.cos(math.rad(i+j))*(r),0)
p[#p+1] = p1 + t
p[#p+1] = p2 + t
p[#p+1] = p3 + t
------------
p[#p+1] = p2 + t
p[#p+1] = p3 + t
p[#p+1] = p4 + t
end
local m = mesh()
m.vertices = p
m:setColors(255,255,255,255)
return m
end
function Shape:rCube(w,h,z,r,n,t) --width,height,depth,edgeRadius,detail
local w,h,z = w/2,h/2,z/2
local t = t or vec3(0,0,0)
local p = {
vec3(-w+r,-h+r,-z),vec3(-w+r,h-r,-z),vec3(w-r,h-r,-z),
vec3(-w+r,-h+r,-z),vec3(w-r,-h+r,-z),vec3(w-r,h-r,-z),--front
vec3(-w+r,-h+r,z),vec3(-w+r,h-r,z),vec3(w-r,h-r,z),
vec3(-w+r,-h+r,z),vec3(w-r,-h+r,z),vec3(w-r,h-r,z),--back
vec3(-w,-h+r,-z+r),vec3(-w,h-r,-z+r),vec3(-w,h-r,z-r),
vec3(-w,-h+r,-z+r),vec3(-w,-h+r,z-r),vec3(-w,h-r,z-r),--left
vec3(w,-h+r,-z+r),vec3(w,h-r,-z+r),vec3(w,h-r,z-r),
vec3(w,-h+r,-z+r),vec3(w,-h+r,z-r),vec3(w,h-r,z-r),--right
vec3(-w+r,h,-z+r),vec3(-w+r,h,z-r),vec3(w-r,h,z-r),
vec3(-w+r,h,-z+r),vec3(w-r,h,-z+r),vec3(w-r,h,z-r),--top
vec3(-w+r,-h,-z+r),vec3(-w+r,-h,z-r),vec3(w-r,-h,z-r),
vec3(-w+r,-h,-z+r),vec3(w-r,-h,-z+r),vec3(w-r,-h,z-r)}--top
self:cubeEdge(p,n,r,0,h,vec3(w-r,0,z-r))
self:cubeEdge(p,n,r,-90,h,vec3(w-r,0,-z+r))
self:cubeEdge(p,n,r,90,h,vec3(-w+r,0,z-r))
self:cubeEdge(p,n,r,180,h,vec3(-w+r,0,-z+r))
self:cubeEdge(p,n,r,0,w,vec3(0,h-r,z-r),1)
self:cubeEdge(p,n,r,-90,w,vec3(0,h-r,-z+r),1)
self:cubeEdge(p,n,r,90,w,vec3(0,-h+r,z-r),1)
self:cubeEdge(p,n,r,180,w,vec3(0,-h+r,-z+r),1)
self:cubeEdge(p,n,r,0,z,vec3(w-r,h-r,0),2)
self:cubeEdge(p,n,r,90,z,vec3(-w+r,h-r,0),2)
self:cubeEdge(p,n,r,-90,z,vec3(w-r,-h+r,0),2)
self:cubeEdge(p,n,r,180,z,vec3(-w+r,-h+r,0),2)
self:cubeCorner(p,n,r,0,0,vec3(w-r,h-r,z-r))
self:cubeCorner(p,n,r,0,-90,vec3(w-r,h-r,-z+r))
self:cubeCorner(p,n,r,0,90,vec3(-w+r,h-r,z-r))
self:cubeCorner(p,n,r,0,180,vec3(-w+r,h-r,-z+r))
self:cubeCorner(p,n,r,-90,0,vec3(w-r,-h+r,z-r))
self:cubeCorner(p,n,r,-90,-90,vec3(w-r,-h+r,-z+r))
self:cubeCorner(p,n,r,-90,90,vec3(-w+r,-h+r,z-r))
self:cubeCorner(p,n,r,-90,180,vec3(-w+r,-h+r,-z+r))
local m = mesh()
for k,v in pairs(p) do v = v + t end
m.vertices = p
m:setColors(255,255,255,255)
return m
end
function Shape:cubeCorner(p,n,r,v,h,t)
local vi = 90/n
for angV = v,v+90-vi,vi do
local h1 = math.cos(math.rad(angV)) * r
local h2 = math.cos(math.rad(angV+vi)) * r
local y1 = math.sin(math.rad(angV)) * r
local y2 = math.sin(math.rad(angV+vi)) * r
for angH = h,h+90-vi,vi do
local p1 = vec3(math.cos(math.rad(angH))*h1,y1,math.sin(math.rad(angH))*h1)
local p2 = vec3(math.cos(math.rad(angH+vi))*h1,y1,math.sin(math.rad(angH+vi))*h1)
local p3 = vec3(math.cos(math.rad(angH))*h2,y2,math.sin(math.rad(angH))*h2)
local p4 = vec3(math.cos(math.rad(angH+vi))*h2,y2,math.sin(math.rad(angH+vi))*h2)
p[#p+1] = p1 + t
p[#p+1] = p2 + t
p[#p+1] = p4 + t
------------
p[#p+1] = p1 + t
p[#p+1] = p3 + t
p[#p+1] = p4 + t
end
end
end
function Shape:cubeEdge(p,n,r,a,l,tr,flip)
local ai = 90/n
for i = a,a+90-ai,ai do
local p1 = math.cos(math.rad(i))*r --x
local p2 = math.sin(math.rad(i))*r
local p3 = math.cos(math.rad(i+ai))*r
local p4 = math.sin(math.rad(i+ai))*r
local x1,y1,z1,x2,y2,z2 = p1,-l+r,p2,p3,l-r,p4
if not flip then
p[#p+1] = vec3(x1,y1,z1)+tr
p[#p+1] = vec3(x2,y1,z2)+tr
p[#p+1] = vec3(x2,y2,z2)+tr
---------------------------
p[#p+1] = vec3(x1,y1,z1)+tr
p[#p+1] = vec3(x1,y2,z1)+tr
p[#p+1] = vec3(x2,y2,z2)+tr
end
if flip == 1 then
x1,y1,z1,x2,y2,z2 = -l+r,p1,p2,l-r,p3,p4
p[#p+1] = vec3(x1,y1,z1)+tr
p[#p+1] = vec3(x2,y1,z1)+tr
p[#p+1] = vec3(x2,y2,z2)+tr
---------------------------
p[#p+1] = vec3(x1,y1,z1)+tr
p[#p+1] = vec3(x1,y2,z2)+tr
p[#p+1] = vec3(x2,y2,z2)+tr
end
if flip == 2 then
x1,y1,z1,x2,y2,z2 = p1,p2,-l+r,p3,p4,l-r
p[#p+1] = vec3(x1,y1,z1)+tr
p[#p+1] = vec3(x1,y1,z2)+tr
p[#p+1] = vec3(x2,y2,z2)+tr
---------------------------
p[#p+1] = vec3(x1,y1,z1)+tr
p[#p+1] = vec3(x2,y2,z1)+tr
p[#p+1] = vec3(x2,y2,z2)+tr
end
end
end

]]>I am a big fan of Codea and coding in general. I am also a big proponent of unit testing (TDD preferably). Since the app doesn't have a unit test framework built in, I recently created one specifically for Codea. If you have a desire for proper unit testing in your projects. Checkout CodeaUnit on GitHub.

CodeaUnit is designed as a library that you simply add as a dependency to any of your own projects that you want unit testing abilities in. It adds a 'CodeaUnit Runner' button to the parameters view when running your code. The runner finds all functions in the app (all tabs) that start with 'test' and runs them for you. All of the features are detailed further on GitHub.

Enjoy, contribute, whatever :)

]]>Using Macbook Pro retina 15" 2012.

]]>Thanks

]]>when I start the app in the simulator (Xcode 6.2), since version 3.2 the screen content is distorted (too wide). After rotation of the ipad the content is displayed correctly. Until version 2.2 everything is displayed correctly. When I run the code in Codea everything works fine. The app is set as portrait_any.

Code: supportedOrientations(PORTRAIT_ANY)

function setup() ...

Has someone the same problem? greetings schuju

]]>```
-- ASLO
-- Use this function to perform your initial setup
supportedOrientations( PORTRAIT_ANY )
function setup()
-- Value for flydirection
value=2
if value == 2 then
physics.gravity( 1, 0)
value=1
else
physics.gravity( -1, 0)
value=2
end
--Set the viewer to fullscreen
--Hide back/pause/play buttons
displayMode( FULLSCREEN )
-- Table to store our physics bodies
bodies = {}
boder = {}
-- Create some static boxes (not effected by gravity or collisions)
local left = makeBox(150, 512, 1040, 1, 90)
left.type = STATIC
local right = makeBox(600, 512, 1040, 1, -90)
right.type = STATIC
local mid = makePlay ( 384, 200, 20, 20, 90)
mid.type = DYNAMIC
table.insert(bodies, left)
table.insert(bodies, right)
table.insert(boder, mid)
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(31, 31, 31, 255)
-- Draw all our physics bodies
for k,body in pairs(bodies) do
drawBody(body)
end
for k,body in pairs(boder) do
drawPlay(body)
end
end
function touched(touch)
-- When you touch the screen, create a random box
if touch.state == BEGAN then
if value == 2 then
physics.gravity( -300, 0)
value=1
else
physics.gravity( 300, 0)
value=2
end
end
end
-- Helper function to create a box using a polygon body
function makeBox(x,y,w,h,r)
-- Points are defined in counter-clockwise order
local body = physics.body(POLYGON,vec2(-w/2, h/2),
vec2(-w/2, -h/2), vec2(w/2, -h/2), vec2(w/2, h/2))
-- Set the body's transform (position, angle)
body.x = x
body.y = y
body.angle = r
-- Make movement smoother regardless of framerate
body.interpolate = true
return body
end
function makePlay(x,y,w,h,r)
-- Points are defined in counter-clockwise order
local body = physics.body(POLYGON,vec2(-10, 10),
vec2(-10, -10), vec2(10, -10), vec2(10, 10))
-- Set the body's transform (position, angle)
body.x = x
body.y = y
body.angle = r
-- Make movement smoother regardless of framerate
body.interpolate = true
return body
end
-- Helper function to draw a physics body
function drawBody(body)
-- Push style and transform matrix so we can restore them after
pushStyle()
pushMatrix()
strokeWidth(1)
stroke(134, 162, 127, 255)
fill(132, 130, 130, 255)
translate(body.x, body.y)
rotate(body.angle)
-- Draw body based on shape type
if body.shapeType == POLYGON then
strokeWidth(3.0)
local points = body.points
for j = 1,#points do
a = points[j]
b = points[(j % #points)+1]
line(a.x, a.y, b.x, b.y)
end
-- Restore style and transform
popMatrix()
popStyle()
end
end
function drawPlay(body)
-- Push style and transform matrix so we can restore them after
pushStyle()
pushMatrix()
local body = physics.body(POLYGON,vec2(-10, 10),
vec2(-10, -10), vec2(10, -10), vec2(10, 10))
body.type = DYNAMIC
sprite("Documents:spcshi", 384, 200, 20, 20)
translate(body.x, body.y)
rotate(body.angle)
-- Draw body based on shape type
if body.shapeType == POLYGON then
local points = body.points
for j = 1,#points do
a = points[j]
b = points[(j % #points)+1]
line(a.x, a.y, b.x, b.y)
end
-- Restore style and transform
popMatrix()
popStyle()
end
end
```

]]>```
displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT_ANY)
function setup()
fontSize(40)
e1=physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
e2=physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))
e3=physics.body(EDGE,vec2(WIDTH,HEIGHT),vec2(WIDTH,0))
tab={}
ball()
tw()
total=0
maxTotal=0
gameOver=false
end
function tw()
t1=tween.delay(10,function() ball() tw() end)
end
function draw()
background(31, 66, 75, 255)
fill(255)
text("High score "..maxTotal,WIDTH/2,HEIGHT-100)
if gameOver then
text("GAME OVER",WIDTH/2,HEIGHT/2+100)
text("Double tap screen to play again.",WIDTH/2,HEIGHT/2)
return
end
text("Current "..total,WIDTH/2,HEIGHT-50)
for a,b in pairs(tab) do
ellipse(b.x,b.y,40)
if b.y<0 then
b:destroy()
table.remove(tab,a)
total=total-#tab
if total<=0 then
gameOver=true
return
end
ball()
end
end
if tb~=nil then
fill(255,0,0)
ellipse(tb.x,tb.y,30)
end
end
function collide(c)
if c.state==BEGAN and not gameOver then
if c.bodyA.info=="tball" and c.bodyB.info=="ball" or
c.bodyA.info=="ball" and c.bodyB.info=="tball" then
total=total+1
maxTotal=math.max(total,maxTotal)
end
end
end
function touched(t)
if t.state==BEGAN then
if gameOver and t.tapCount==2 then
restart()
return
end
if tb then
tb:destroy()
end
tb=physics.body(CIRCLE,15)
tb.x=t.x
tb.y=t.y
tb.restitution=1
tb.info="tball"
tb.type=STATIC
end
end
function ball()
b=physics.body(CIRCLE,20)
b.x=math.random(50,WIDTH-50)
b.y=math.random(HEIGHT-200,HEIGHT)
b.restitution=1
b.info="ball"
b.gravityScale=.5
table.insert(tab,b)
end
```

]]>Here is my version of an archive manager:

https://gist.github.com/anonymous/fc8e3231a52b9709c406

In a nushelll:

- the project is saved inside the project, with a tab named zzz_001, zzz_002 etc...

- you can save an archive when you want.

- you can add a note to the archive.

- you can restore from an archive (an archive of the current project is automatically created before restoring).

- you can delete an archive, or all at once.

- you can copy a project without the archives (to share it for instance).

- One limit: the Main tab must be the first tab (this is because the Main tab cant be deleted).

How to use it:

- make a dependency to the project.

- in your setup put this as the first line, and uncomment the line when you want to make an archive.

```
function setup()
-- if XFCarchiver then XFCarchiver() return end -- uncomment this line to manage archives
```

Here is the top level screen shot

and a screenshot from an archive.

Comments/suggestions/ improvements welcome

]]>