All Discussions - Codea http://www.twolivesleft.com/Codea/Talk/discussions/feed.rss Thu, 17 May 12 01:47:53 -0400 All Discussions - Codea en-CA Frustrations http://www.twolivesleft.com/Codea/Talk/discussion/1000/frustrations Sun, 13 May 2012 20:30:37 -0400 LadyJayne 1000@/Codea/Talk/discussions I have been playing with Codea for a few weeks now, and I'm really having a hard time wrapping my brain around the language. I will admit that I am not a programmer, but have dabbled, and want to learn. I have been reading the references, example codes (learned some things through manipulating them), and have done the tutorials. I have done my own coding and was able to draw an ellipse and square. I even applied some gravity to the shapes to make them move according to the tilt of the iPad. I just don't know where to go from there. This is not like GML (I think that is object based programming?), and I feel stuck.

Sorry for the venting. I think Codea is really neat. People can do super cool things with it. I just wish I understood it more, and that there was better explanation why you use certain code to do certain things. I will keep plugging along.

]]>
Code for a fps camera http://www.twolivesleft.com/Codea/Talk/discussion/1020/code-for-a-fps-camera Wed, 16 May 2012 23:31:07 -0400 Nicbit 1020@/Codea/Talk/discussions Im new to codea and lua ( and processing) but i am an experienced c++ programmer (and now I'm porting my games to the iPad:)). Im rewriting one of the games (it allows the user to become familiarized with programming through the use of a c++ shell who's code is then integrated into the games code(actually a compiler which inserts it into the gamecode compiles and executing while resuming the screen) I already have the game made( programmed it many years ago) and I am using Codea (from c++ to lua) to port it to the iPad. So far I have the fps camera, it has 2 files, the level and the game mechanics. By the way, it works by moving/rotating the world around a statanary camera. Anyway hear is the code:

MAIN: http://pastebin.com/py8Ckt3Z TEST2:http://pastebin.com/1mUTVjgA

-Nicholas P.s.it may lag If you have an iPad 1 P.p.s. I will probably post up source for shell in a few days P.p.p.s Any reccomendations would be appreciated P.p.p.p.s sorry if I posted this in the wrong location

]]>
3D FPS Game http://www.twolivesleft.com/Codea/Talk/discussion/1004/3d-fps-game Mon, 14 May 2012 21:13:20 -0400 Sillibird 1004@/Codea/Talk/discussions A long time ago, I really wanted to make a 3D shooter game in codea. That was when I was starting learning codea and I didn't know much so it turned out to be a horrible 2d shooter with loads of bugs. Recently(Well not that recent) I picked up the idea again. At that point I gained more knowledge with 3D etc. So, after countless hours of work, I have finished with my first stable beta build of the game. The game features: A menu Working options screen 1 playable map, Full character movement(Walking, Jumping etc.), Randomly occurring opponents, Health and damage, 7 different weapons

I will post a video tomorrow because I have worked a lot today to get to a stable build. The code is a bit to big to post(57,389 lines of code)

I plan to add: A campaign mode, A multiplayer mode, Zombies mode

The FPS is IPad 1-15, iPad 2-21, iPad 3-11

More soon!

(Feedback greatly appreciated!)

]]>
Is the app built from codea able to release to apple app store? http://www.twolivesleft.com/Codea/Talk/discussion/1019/is-the-app-built-from-codea-able-to-release-to-apple-app-stores Wed, 16 May 2012 19:55:36 -0400 Bluedolphin 1019@/Codea/Talk/discussions Just curious

]]>
Base Class Member Becomes Nil http://www.twolivesleft.com/Codea/Talk/discussion/1017/base-class-member-becomes-nil Wed, 16 May 2012 17:13:58 -0400 MatthewMurdoch 1017@/Codea/Talk/discussions I'm struggling with a nuance of OO and inheritance in Codea. I have the code below, which given my understanding should function correctly:

--# Main
function setup()
    local base = Base()
    base:incrementIntMember()
    print("----")
    local derived = Derived()
    derived:incrementIntMember()
end

--# Base
Base = class()

function Base:init()
    print("In Base:init()")
    self.i = 1
end

function Base:incrementIntMember()
    print("In Base:incrementIntMember()")
    self.i = self.i + 1
end
--# Derived
Derived = class(Base)

function Derived:init()
    print("In Derived:init()")
    Base:init(self)
    -- Also doesn't work
    --Base:init()
end

However, when I run it it gives the following output:

In Base:init()
In Base:incrementIntMember()
----
In Derived:init()
In Base:init()
In Base:incrementIntMember()
error: [string "Base = class()..."]:10: attempt to perform arithmetic on field 'i' (a nil value)
Pausing playback

It's not clear to me why 'self.i' is nil in the case where the object being called derives from the base. The base class' constructor (init) is being called from the derived class' constructor so 'self.i' is initialized. I'm guessing that perhaps there are two 'selfs' in this situation (one for the base part of the object and one for the derived part) but that is counter to my experience in other languages...

Any enlightenment would be appreciated!

]]>
More intuitive 3d example http://www.twolivesleft.com/Codea/Talk/discussion/1018/more-intuitive-3d-example Wed, 16 May 2012 17:19:46 -0400 KMEB 1018@/Codea/Talk/discussions

 function setup()
    camspot = vec3(0,0,0)
parameter("distance",100,1000,440)
parameter("angle",0,360,45);    
parameter("topangle",-89,89,0)
parameter("fov",65,144,100)
parameter("camerax",-100,100,0)
parameter("cameray",-100,100,0)
parameter("cameraz",-100,100,0)
definefacerot()
watch("fps")
noSmooth()

rectMode(CENTER)

end


function draw()


    background(134, 166, 179, 255)
    
    
    cam()
    
for i = -3,3 do
    for j = -3,3 do
    drawcube(i*12,0,j*12,red,12,24)

    end
    end
 drawcube(6,32,6,
"SpaceCute:Background",32,24,nil, CurrentTouch.x,CurrentTouch.y)
end
function definefacerot()
    
   red = setflat(color(255, 0, 0, 255))
blue = setflat(color(0, 0, 255, 255))
green = setflat(color(0, 255, 0, 255))
black =setflat(color(3, 3, 3, 255))
dark =setflat(color(33, 34, 35, 255))

local face = {

{90,1,0,0}, -- north     3
 {180,1,0,0}, --back   2
 {0}, --front        1

{270,0,1,0}, -- west     6
{90,0,1,0}, -- east      5
{270,1,0,0}, -- south    4

nil
}


cubefacerot= face
end

function setflat(culurr)
    
local cull = image(1,1)

cull:set(1,1,culurr)

return cull
end

function drawcube(xx,yy,zz,tex,size,shading,rra,rrb,rrc)
    if shading == nil then shading = 0 end
    pushMatrix()
    translate(xx,yy,zz)
    if rra == nil then else rotate(rra) end
     if rrb == nil then else rotate(rrb,1,0,0) end
     if rrc == nil then else rotate(rrc,0,0,1) end
    scale(size/64,size/64,size/64)
    pushMatrix()
    for i = 1,6 do
        pushMatrix()
rotate(unpack(cubefacerot[i]))
if shading > 0 then
        tint(255-(i)*shading) end
        translate(0,0,-32)
        sprite(tex,0,0,64)
        popMatrix()
--rect(i*111,0,99,99)
 end
noTint()
popMatrix()
popMatrix()
popMatrix()
end
    
    function cam() 
    
       camspot = vec3(camerax,cameray,cameraz)
    topangle = math.min(89.9,math.max(-89.9,topangle))
    fps = 0.1 * math.ceil( DeltaTime*600)
 --   rotate(yaw)
    pushMatrix()
    perspective(fov, WIDTH/HEIGHT)
    local camdown = vec2(distance/(fov/44),0):rotate(math.rad(topangle))
    
local camplane = vec2(camdown.x,0):rotate(math.rad(angle))

    camera(camplane.x+camspot.x,camdown.y+camspot.y,camplane.y+camspot.z, camspot.x,camspot.y,camspot.z, 0,4,0)
    
    end
]]>
Trig example http://www.twolivesleft.com/Codea/Talk/discussion/945/trig-example Sat, 05 May 2012 11:21:02 -0400 TechDojo 945@/Codea/Talk/discussions In order to test out my new BT keyboard (and given that Codea was designed to look like the Processing language) I decided to convert one of the Processing trigonemtry examples to Lua. The orginal example can be found at http://processing.org/learning/trig/ and is a useful guide to anyone learning about sine, cosine etc, the lua code is given below. :)

--[[ Sine Console
* Processing: Creative Coding and
* Computational Art
* By Ira Greenberg */
* Ported to Lua by Jon Howard (techdojo@gmail.com)
* Original post http://processing.org/learning/trig/
--]]

local px, py, px2, py2
local angle = 0 
local angle2 = 0
local radius = 100
local frequency = 2
local frequency2 = 2
local x=0
local x2=0

function setup()
    displayMode(FULLSCREEN)
end

function draw()
    translate(-50,(HEIGHT/2)-radius/2)  -- move the drawing to the center of the screen
    background (127)
    noStroke()
    
    fill(255)
    ellipse(WIDTH/8, 75, radius, radius)
     
    --rotates rectangle around circle
    px = WIDTH/8 + math.cos(math.rad(angle))*(radius/2);
    py = 75 + math.sin(math.rad(angle))*(radius/2);
    rectMode(CENTER)
    fill(255, 0, 0, 255)
    rect (px, py, 10, 10)        -- draw the rect on the edge of the circle
    stroke(222, 0, 255, 255)
    strokeWidth(5)
    line(WIDTH/8, 75, px, py)
 
    angle2 = 0
    fill(0)
    -- draw static curve - y = sin(x)
    for i=1,WIDTH do
        px2 = WIDTH/8 + math.cos(math.rad(angle2))*(radius/2);
        py2 = 75 + math.sin(math.rad(angle2))*(radius/2);
        point(WIDTH/8+radius/2+i, py2)
        angle2 = angle2 - frequency2
    end

    -- send small ellipse along sine curve
    -- to illustrate relationship of circle to wave
    noStroke()
    fill(8, 0, 255, 255)
    ellipse(WIDTH/8+radius/2+x, py, 15, 15)
    angle = angle - frequency
    x = x + 1

    -- when little ellipse reaches end of window
    -- reinitialize some variables
    if (x>= WIDTH-60) then
        x = 0
        angle = 0
    end

    -- draw dynamic line connecting circular
    -- path with wave
    strokeWidth(3)
    stroke(0, 255, 66, 255)
    line(px, py, WIDTH/8+radius/2+x, py)

    -- output some calculations
    fill(0)
    textAlign(LEFT)
    text("y = sin x",   180, 225)
    text("px = " .. px, 180, 205)
    text("py = " .. py, 180, 185)
end
]]>
Error Capture http://www.twolivesleft.com/Codea/Talk/discussion/1016/error-capture Wed, 16 May 2012 12:05:04 -0400 Bri_G 1016@/Codea/Talk/discussions Hi All,

I have a recurrent problem in which I keep making errors, mainly logistic, but sometimes technical. But, I don't seem to know how to resolve some of them. Like the following - I have an array which keeps throwing up errors in use or in trying to print out the array. One of the elements in the array must be duff - but I can't find which one.

Here is an example of the array, trying to set up a 3D matrix. Is there any way in which we could get Codea to run through the procedure and print out to a file/screen so that I could identify the element. Instead I get the printout:

main.lua:27: attempt to concatenate field '?' (a nil value) - which is not very helpful - I need to trap the error.

function setup()
    --
    points = { x = {}, y = {}, z = {}}
    radius = 100
    antorad = math.pi/180
    index = 1
    for i = 0, 360, 30 do
        for j = 0, 360 do
            points.x[i] = radius * math.sin(i * antorad) * math.cos(j * antorad)
            points.y[i] = radius * math.sin(i * antorad) * math.sin(j * antorad)
            points.z[i] = radius * math.cos(i * antorad)
            index = index + 1
        end
    end

end

function draw()
    --
    for loop = 1, index do
        text("Array is "..loop.." x: "..points.x[loop].." y: "..points.y[loop].." z: "..points.z[loop], 100, 200+loop*20)
    end
end

May, or may not, be relevant but the code and error were taken from Love2D - which I tend to use for early trials.

Any suggestions?

Thanks.

Bri_G

:)

]]>
Timing? http://www.twolivesleft.com/Codea/Talk/discussion/1015/timings Wed, 16 May 2012 04:32:33 -0400 ivanassen 1015@/Codea/Talk/discussions Speaking of optimization: what is a good precise way to measure the time in Codea?

os.time seems to return time in seconds since the Unix epoch, it seems, but stored in a float. The precision of the float mantissa isn't enough, so os.difftime returns zero for small intervals.

os.clock returns weird things - at least they increase monotonically.

It would be nice to have a function that returns precise milliseconds since the start of the game (not the start of Codea).

]]>
luasandbox and missing functionalities http://www.twolivesleft.com/Codea/Talk/discussion/1011/luasandbox-and-missing-functionalities Tue, 15 May 2012 18:56:34 -0400 shrike 1011@/Codea/Talk/discussions I was looking for implementing a class with setter / getter methods but I got stuck against the lack of rawget / rawset facilities in current codea version. I also found some discussion about modding codea changing the luasandbox file, and I wonder if it would be enough to enable the missing rawget/set. There's some specific reason why not having them available? Considering also that, if I understood right, there're some feature of codea that rely on them (like retina reso,ution support).

Also the 'require' keyword is not available. again there is a specific reason (something to do withso e restriction or limit) or is something we could hope to have in future versions?

Anyway, if features like that would be enabled by modding the sandbox file, what could we expect? Everithing working? bugs? Unexpected behaviours? Has someone tried before? and more over, there would be problem to release a game with codea runtime libs in that case?

]]>
Top down shooter http://www.twolivesleft.com/Codea/Talk/discussion/997/top-down-shooter Sun, 13 May 2012 15:50:24 -0400 KMEB 997@/Codea/Talk/discussions

  

Pleased to say that codea seems fully capable of supporting dozens of thinking AIs at once in a complex environment....

]]>
Battle Chips -- Updated http://www.twolivesleft.com/Codea/Talk/discussion/857/battle-chips-updated Fri, 20 Apr 2012 21:26:33 -0400 Mark 857@/Codea/Talk/discussions UPDATE

A new video to show the project at 0.50. As per several suggestions, I'm going to add some additional challenges (Laser Skeet -- blast a set of fast moving targets, Maze Race -- be the first bot to reach the goal,, Chip Chase -- track down and collect wandering prizes) in addition to the standard "zap the other bot" exercise. That will mean some fairly big changes in the structure.

So I thought I'd show "classic" BC before I rip it apart. Comments not just welcome, but really really needed.


Original Post

After finally trying out the wonderful Cargo Bot, I got inspired to knock around my own drag and drop programming toy. Battle Chips is a new take on battling robot games going back to Robot Wars. It's incomplete, but after a long day trapped in waiting rooms, I think I made good progress.

Now I need some suggestions for additional programming chips, ways to implement varied bot hardware, and a system for exchanging bots with others.

]]>
Matrix rotation problems http://www.twolivesleft.com/Codea/Talk/discussion/1009/matrix-rotation-problems Tue, 15 May 2012 16:44:54 -0400 Vega 1009@/Codea/Talk/discussions I think I must be doing something completely wrong. What I want to achieve is a triangle that rotates to point at a dot. I started out by Using the formula angle = math.deg(atan2(y2-y1,x2-x1)), then when failing, I tried creating vec2s and using angle = math.deg(vec2a:angleBetween(vec2b)). Still not pointing correctly. Maybe I am doing my rotation wrong. I would appreciate any help getting this working. Please see code below, my intent was that the triangle should always point at the dot, regardless of the value of the parameters

function setup()
    parameter("x1",100,600,100)
    parameter("y1",100,600,100)
    parameter("x2",100,600,400)
    parameter("y2",100,600,400)
end

function draw()
    vec2a = vec2(x1,y1)
    vec2b = vec2(x2,y2)
    myangle = vec2a:angleBetween(vec2b)
    background(40, 40, 50)
    strokeWidth(5)
    stroke(0, 0, 0, 255)
    --print the target to point at
    ellipse(x1,y1,5,5)
    pushMatrix()
    --now I translate to where I want to draw my triangle
    --then I rotate to the angle
    --and draw 
    translate(x2,y2)
    rotate(math.deg(myangle))
    drawtriangle()
    popMatrix()
end

function drawtriangle()
    strokeWidth(8)
    stroke(255, 255, 255, 255)
    line(0,0,20,-60)
    line(20,-60,-20,-60)
    line(-20,-60,0,0)
end

Any tips appreciated, thanks.

]]>
How can I include videos and pictures in posts? http://www.twolivesleft.com/Codea/Talk/discussion/1010/how-can-i-include-videos-and-pictures-in-postss Tue, 15 May 2012 17:03:51 -0400 pepinganos 1010@/Codea/Talk/discussions I've seen you put images and Youtube videos in your posts. How do you do that?

]]>
Transparent painting with feather effect http://www.twolivesleft.com/Codea/Talk/discussion/1013/transparent-painting-with-feather-effect Wed, 16 May 2012 03:43:47 -0400 pepinganos 1013@/Codea/Talk/discussions I made this little think.

You can paint with real transparency.

function setup()     parameter("red",0,255,244)     parameter("green",0,255,100)     parameter("blue",0,255,100)     parameter("alpha",0,255,200)     parameter("thickness",1,80,25)     iparameter("cap",0,2,0)     iparameter("feather",0,1,0)     myDrawing=image(WIDTH,HEIGHT)     myBack=image(WIDTH,HEIGHT) end function draw()     local v,t,angle     if(CurrentTouch.state==BEGAN or CurrentTouch.state==MOVING) then         if(feather==1) then             v = vec2(CurrentTouch.x,CurrentTouch.y)                 -vec2(CurrentTouch.prevX,CurrentTouch.prevY)             angle = v:angleBetween(vec2(1,-1))             t = thickness * math.abs(math.cos(angle))+5         else              t = thickness         end             strokeWidth(t)         lineCapMode(cap)         stroke(red, green, blue, 255)         setContext(myDrawing)         tint(255, 255, 255, 255)         line(CurrentTouch.prevX,CurrentTouch.prevY,CurrentTouch.x,CurrentTouch.y)     else         setContext(myBack)         tint(255, 255, 255, alpha)         sprite(myDrawing,WIDTH/2,HEIGHT/2)         setContext(myDrawing)         background(0,0,0,0)                      end     setContext()     background(0, 0, 0, 255)     tint(255, 255, 255, 255)     sprite(myBack,WIDTH/2,HEIGHT/2)     tint(255, 255, 255, alpha)     sprite(myDrawing,WIDTH/2,HEIGHT/2) end

BTW I'm a musician, did you notice :-)) ?

]]>
Bouncing within a circle http://www.twolivesleft.com/Codea/Talk/discussion/1012/bouncing-within-a-circle Wed, 16 May 2012 02:43:25 -0400 Doffer 1012@/Codea/Talk/discussions Hi all,

I'm quite stuck with my next bit of code:

displayMode(FULLSCREEN)


-- Use this function to perform your initial setup
function setup()
    pos = vec2(WIDTH/2, HEIGHT/2)
    speed = vec2(300, 134)
    time = 0
    center = vec2(WIDTH/2, HEIGHT/2)
    diameter = 750
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)
    
    ellipse(center.x, center.y, diameter)

    -- This sets the line thickness
    strokeWidth(5)
    sprite("Planet Cute:Star", pos.x, pos.y)
    
    
    time = DeltaTime
   
    pos.x = pos.x + time * speed.x
    pos.y = pos.y + time * speed.y   

    -- if the new position is outside or on the ellipse
    if pos:dist(center) >= diameter/2 then
        -- calculate the new speed direction
        angle = math.atan2(pos.x-center.x,pos.y-center.y)
        pcol=vec2(math.cos(angle)*375, math.sin(angle)*375)
        vecn = vec2(-pcol.x, -pcol.y):normalize()
        dotn=vecn:dot(vecn)
        dot=speed:dot(vecn)
        imp = dot/dotn
        speed.x = speed.x - imp * vecn.x * 2
        speed.y = speed.y - imp * vecn.y * 2
   
        -- update the new position
        pos.x = pcol.x + speed.x + center.x
        pos.y = pcol.y + speed.y + center.y
    end
end


I want the star to bounce within the circle. I can't get the math right. Anyone an idea what I'm doing wrong here?

]]>
Mandelbrot - some simple changes http://www.twolivesleft.com/Codea/Talk/discussion/1014/mandelbrot-some-simple-changes Wed, 16 May 2012 04:30:12 -0400 ivanassen 1014@/Codea/Talk/discussions Played around with the Mandelbrot example last night. Here's a faster version with some minor changes:

https://gist.github.com/288c44efa63465970a1b

What's changed:

  • local variables are much faster in Lua than global - so it pays to declare your inner loop vars as local; this led to a 15% improvement of the initial zoom, and higher when you zoom in (and the iterations of the inner loop go up)

  • instead of updating a single row from the image and drawing all of it, switch the backingMode to RETAINED, use a image consisting of a single row and draw only this image at the appropriate position on the screen. This led to a 2x improvement of the initial zoom.

]]>
Cargo-Bot: Help my logic http://www.twolivesleft.com/Codea/Talk/discussion/1007/cargo-bot%3A-help-my-logic Tue, 15 May 2012 11:44:59 -0400 anakowi 1007@/Codea/Talk/discussions Puzzle: #11 Color Sort (Easy)

I'm starting this discussion topic, which I may need to revisit for some further help with my logic for other puzzles.

Maybe I'm not understanding how each tool works OR maybe this is a glitch...

My sequence so far seems to repeat a step that it shouldn't. Without an instruction to move I expect the sequence to stop however it goes back one register and repeats. I don't understand why?

Please, I don't want to look at the full solution yet. I only want to first understand what is wrong with my logic sequence before I finish perfect and earn my 3 stars!

At the moment it looks like this:

Prog1. Down redLeft redP2 greenRight Down Left

Prog2. Down Right P1

When I step through the sequence this is what happens:

First 2 red boxes are deposited in the first column. The green box is put in the right column and the hoist backs up to centre - then it should stop but it doesn't.

It goes back one register and picks up the third red box reusing the 5th register in the sequence then continues to the 6th register (move left), then repeats 5th again (drop box) and 6th again move left - smash!

Why is it doing this loop?

*edit: I got my 3 stars - 9 registers :)

]]>
Is there a simple way to get the name of the current class I am in? http://www.twolivesleft.com/Codea/Talk/discussion/998/is-there-a-simple-way-to-get-the-name-of-the-current-class-i-am-ins Sun, 13 May 2012 16:34:32 -0400 joetheengineer 998@/Codea/Talk/discussions I would like to be able to programmatically retrieve the name of the current class I am in. Is there a straightforward way to achieve this?

In passing, if getting the name of the current function is possible, that would be great as well.

]]>
Function Syntax http://www.twolivesleft.com/Codea/Talk/discussion/1008/function-syntax Tue, 15 May 2012 15:53:35 -0400 Munkie 1008@/Codea/Talk/discussions More simpleton questions, sorry in advance, but thanks in advance for your patience.

I am having an issue wrapping my head around functions. How to call them? Do they work in a linear fashion, and you do not have to call them? How do you pass parameters, why sometimes the are formatted as such:

function EnemyHorde:init()

and other times:

function setTest(t)

and sometimes just:

function nextTest()

I am having a problem locating a function tutorial or syntax definition. I have searched in the forums, and also the reference. I have looked at LUA specific references and I am still at a loss.

If you can point me to a reference for a beginner that would be great, or at least a few simple examples or exercises.

Thanks again, Munkie

]]>
loveCodea - loveCodify revived http://www.twolivesleft.com/Codea/Talk/discussion/849/lovecodea-lovecodify-revived Fri, 13 Apr 2012 17:23:18 -0400 Codeslinger 849@/Codea/Talk/discussions Hello gamers and programmers!

I've seen Asteroys (http://twolivesleft.com/Codea/Talk/discussion/669), but instead of loading it on to my iPad I thought it may be a good idea to get it running on the desktop.

I've taken the loveCodify wrapper, adapted it for LÖVE 0.8.0 and added some functionality until I got Asteroyds running. Like loveCodify, I did enough to get this game running so it isn't a complete wrapper either. I hope that I can revive interest in it, however.

I'm not a githubber (yet?), so find the new Lua file on pastebin (for one month) and the original luaCodify on github (see file header):

http://pastebin.com/GFyVZnL5

Detailed instructions to get Asteroyds running:

Copy "Asteroyds.spritepack" as "Asteroyds" into the source code directory.

Copy "Tyrian Remastered.spritepack" (extract it from the Codea app) as "Tyrian Remastered" into the source code directory.

Copy "loveCodea.lua" and "vector.lua" (from the original github repo) into the source code directory.

Make a "conf.lua" like this:

function love.conf(t)
    t.title = "Asteroyds"
    t.author = "Hyro Vitaly Protago"
    t.screen.width = 1024
    t.screen.height = 768
end

Add this to the top of "Main.lua":

if require ~= nil then
    require("loveCodea")
    require("Interface")
    require("Menu")
    require("Rules")
    require("Plateau")
    require("Pilote")
    require("Vaisseaux")
    require("Chrono")
    require("Des")
    require("Asteroyds")
    require("OrientationAsteroyds")
    require("Move")
    require("AnotherMove")
    require("MoveA")
end

Run it!

-- Stephan

]]>
Tip for copying/pasting code http://www.twolivesleft.com/Codea/Talk/discussion/1005/tip-for-copying-pasting-code Mon, 14 May 2012 22:17:12 -0400 Keebo 1005@/Codea/Talk/discussions As a newbie myself, I enjoy and learn when people post code on the forum or other websites. Sometimes the code doesn't run and I scratch my head and wonder why. I have found many times that email in the iPad only downloads a certain amount of code (if the code is long) and leaves a button to completely download the rest of the code at the bottom of the email. Many of you know this already but for those who may not know, it may be a good habit to scroll to the bottom of the emailed code to make certain.

Another tip along the same lines. Several examples are posted on websites as *.codea files. Most of the time they don't come up as full files in my default program of choice. Another thread suggested using the free Notepad++ as a coding environment but it works great for opening such files. A few modifications have to be made to the *.codea files but they are quite obvious.

I know this is old news to most of the old salties here but hopefully as new users come aboard they may find this useful.

Cheers,

Keebo

]]>
Find and Replace in the editor http://www.twolivesleft.com/Codea/Talk/discussion/1006/find-and-replace-in-the-editor Tue, 15 May 2012 08:28:24 -0400 TechDojo 1006@/Codea/Talk/discussions Not sure if this has already been implemented (or suggested) so please excuse me if it has. Is basic find and or replace functionality available in the editor?

If not it would certainly make for a useful addition :)

]]>
How do you "stop" execution of a program? http://www.twolivesleft.com/Codea/Talk/discussion/988/how-do-you-stop-execution-of-a-programs Sat, 12 May 2012 13:54:57 -0400 fglette 988@/Codea/Talk/discussions Thanks to Codea, I have taken up coding again after many years away. Love the program and currently working on my first apps.

I have run into a problem figuring out how to stop execution of a program when a certain condition is met. I am trying to use a counter that counts down from a set starting number down to zero. When zero is reached, I want the loop to stop, run a function to determine win/lose state and take necessary actions. My code counts down fine and reaches zero, does it's thing and prints the message on the screen. But code continues to count down, in want the code to stop executing at this point and reset wait for user inout to start over. I believe this is because Codea's draw function is constantly being called. I have searched code samples and forums, but can't find anything that shows how to "stop" the draw loop. My code is posted below. Any help on subject is most appreciated.

-- track gametime and set gameover state
function gametime()
    gtime = gtime - 1
    -- print (gtime)
    if gtime == 0 then 
        gameover = true
    end
end

-- reset game when countdown timer reaches zero
function resetgame()
    gtime = 100
    gameover = false
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)
    -- Move to the middle of the screen
    pushMatrix()
    translate(WIDTH/2, HEIGHT/2)
    -- not sure what this line does:
    popMatrix()
    -- Draw our gemMesh
    gemMesh:draw()
-- keeps track of game time   
    gametime()
    text("Time Remaining: "..gtime, 175, HEIGHT - 25)
    if gameover then
        text("OUT OF TIME!!", WIDTH/2, HEIGHT/2)
        -- sound(DATA, "ZgBAKQBIQEBAQEBAAAAAAMaB4T7x8M8+QABAf0BAQEBAc0BA")
        resetgame()
    end     
end
]]>
Voxel shader engine- code released http://www.twolivesleft.com/Codea/Talk/discussion/982/voxel-shader-engine-code-released Fri, 11 May 2012 20:27:47 -0400 KMEB 982@/Codea/Talk/discussions

Might be releasing this soon... Look, there it is https://docs.google.com/document/d/1n-4vmeiq8OAAzRSHNNklU7p1GXH-fWKbq51LH7kSy0Y/mobilebasic

]]>
Function plotter http://www.twolivesleft.com/Codea/Talk/discussion/1003/function-plotter Mon, 14 May 2012 13:13:42 -0400 pepinganos 1003@/Codea/Talk/discussions It's my first Codea program. You can zoom and pan with your fingers. The grid can be deactivated. You can write your own functions in "function fn(x)".


function fn(x)     return math.sin(x*2) + math.sin(x) end function setup()     center=vec2(WIDTH/2,HEIGHT/2)     pos=vec2(0,0)     size=100     touches = {}     lineCapMode(2)     --noSmooth()     iparameter("Grid",0,1,1)     --watch("myW") end function draw()     local fnI, prevI, prevFnI, move, dist     left=fromScreen(vec2(0,0))     right=fromScreen(vec2(WIDTH,0))     top=fromScreen(vec2(0,HEIGHT))     bottom=fromScreen(vec2(0,0))     background(0, 0, 0, 255)          drawAxis()              --draw function     stroke(101, 239, 18, 255)     strokeWidth(4)     prevI = nil     for i = left.x, right.x, (right.x-left.x)/700 do         fnI = fn(i)         if (prevI~=nil) then myLine(vec2(i,fnI),vec2(prevI,prevFnI)) end         prevI = i         prevFnI = fnI     end          --zooming and moving     n = nbTouches()     if(n==1) then         move = vec2(CurrentTouch.prevX-CurrentTouch.x,CurrentTouch.prevY-CurrentTouch.y)         pos = pos - move/size         zooming=false     elseif(n==2) then         if (zooming==true) then             size=size0*distanceBetweenFingers()/dist0             move = vec2(CurrentTouch.prevX-CurrentTouch.x,CurrentTouch.prevY-CurrentTouch.y)             pos = pos - move/size         else             zooming=true             dist0=distanceBetweenFingers()             size0=size         end     else         zooming=false         end end function touched(touch)     if touch.state == ENDED then         touches[touch.id] = nil     else         touches[touch.id] = touch     end end function nbTouches()     local n     n=0     for i,j in pairs(touches) do         n = n + 1     end     return n end function distanceBetweenFingers()     local v, sign     v=vec2(0,0)     sign=1     for i,j in pairs(touches) do         v=v+vec2(j.x,j.y)*sign         sign=-1     end     return v:len() end function toScreen(v)     return center + (v + pos) * size end function fromScreen(v)     return (v - center) / size - pos end function myLine(va,vb)     local v1,v2     v1 = toScreen(va)     v2 = toScreen(vb)     line(v1.x,v1.y,v2.x,v2.y) end function drawAxis()     local v,i     stroke(38, 0, 255, 255)     strokeWidth(4)     i=fromScreen(vec2(60,0)).x - fromScreen(vec2(0,0)).x     i=nearestInterval(i)          for x=math.floor(left.x/i)*i,right.x,i do         v=toScreen(vec2(x,0))         gridVerLine(v.x)         line(v.x,v.y+5,v.x,v.y-5)         text(x,v.x-15,v.y-10)     end     for y=math.floor(bottom.y/i)*i,top.y,i do         v=toScreen(vec2(0,y))         gridHorLine(v.y)         line(v.x+5,v.y,v.x-5,v.y)         text(y,v.x-15,v.y-10)     end     stroke(38, 0, 255, 255)     strokeWidth(4)     myLine(vec2(-1000000,0),vec2(1000000,0))     myLine(vec2(0,-1000000),vec2(0,1000000)) end function gridVerLine(x)     if (Grid == 0) then return end     pushStyle()     stroke(92, 87, 99, 255)     line(x,0,x,HEIGHT)     popStyle() end function gridHorLine(y)     if (Grid == 0) then return end     pushStyle()     stroke(92, 87, 99, 255)     line(0,y,WIDTH,y)     popStyle() end function nearestInterval(n)     local i1, i2, i3     i=1     i2=2.5     i3=5          while true do         if(n>i and n<i*10)then break         elseif(n<i) then i=i/10         else i=i*10         end     end     if (n>i and n<i2*i) then return(i)     elseif (n>i2*i and n<i3*i) then return(i2*i)     else return(i3*i)     end end

BTW, how can I insert images in my posts?

]]>
how to place sprite on center instead of bottom left http://www.twolivesleft.com/Codea/Talk/discussion/1001/how-to-place-sprite-on-center-instead-of-bottom-left Mon, 14 May 2012 12:02:40 -0400 codeusr 1001@/Codea/Talk/discussions I am new to lua and game programming in general so bear with me...

So i have created a new class called Player and have in the draw() function

sprite("image ... ", CurrentTouch.x, CurrentTouch.y)

but this starts the sprite from bottom left... how can i add it in the center before i can move it?

]]>
Interacting with the world http://www.twolivesleft.com/Codea/Talk/discussion/1002/interacting-with-the-world Mon, 14 May 2012 12:50:07 -0400 bdahlem 1002@/Codea/Talk/discussions I'm pretty new to Codea, but find that it does have some great use for prototyping and quick one-off ideas. One thing I'm interested in is working with external devices. I know that sockets have come and gone from the API, and url support is coming, but here's another idea...

Would it be possible in any way to add support for a device such as this iOS-serial cable http://www.redpark.com/c2db9.html or this homebrew headphone jack interface http://code.google.com/p/hijack-main/ ? It would be another way to bring another aspect of Processing to the iOS world.

]]>
vec2 bug? http://www.twolivesleft.com/Codea/Talk/discussion/16/vec2-bugs Sat, 29 Oct 2011 15:49:14 -0400 ruilov 16@/Codea/Talk/discussions v1 = vec2(1,0)

v2 = vec2(-1,0)

v1:angleBetween(v2) <- returns 2.14. Should be +pi or -pi

Hopefully I'm not missing something super simple

]]>
draw hole in image context? http://www.twolivesleft.com/Codea/Talk/discussion/989/draw-hole-in-image-contexts Sat, 12 May 2012 15:37:06 -0400 tnlogy 989@/Codea/Talk/discussions is it possible to erase data from an image. I draw a rect to an image context, and then try to use noFill() to draw a hole in the rect, but nothing seems to happen. any ideas?

]]>
best scrolling http://www.twolivesleft.com/Codea/Talk/discussion/999/best-scrolling Sun, 13 May 2012 17:02:30 -0400 Inviso 999@/Codea/Talk/discussions hey guys and girls...

first, thanks TLL for Codea, i'm just loving it! and your community here is great too, so i want to get your opinions (it's not something i usually do) i want to create a game and i want to sell it in the appstore (like many of you too) but it would be my first game to publish.

Its a ShootEmUp, nothing extremely special, just fun action, a little story, ipad-created graphics, hopefully ipad created music in the background (and i plan to share that if i get it to work playing mp3's in the background)

the game should have 4 worlds, a world consists of a space section, like this:

and the you proceed on the planet, near above ground... and i wish i had a great idea to do the scrolling on the planet.... what comes to my mind is one of these options: 1 draw the elements one by one, so if i have e.g. a street going from left to right, that could consist of 20 tiles... or green grass, that could fill the screen completely, i think that could be too slow... so i would have to make it less detailed...

2 draw "pre rendered" larger sprites... so i would have maybe just 4-5 sprites for the background, which get created on the fly as the level proceeds with context() to a sprite image out of the litle ones...

3 just use primitives and be very creative making it look good

any suggestions about speed, any other ideas etc?

i would love to hear from you...

i made everything in this video, and i do plan making everything in the game by myself... The slowdowns are just by recording

]]>
Ludum Dare with Codea and Löve Codify http://www.twolivesleft.com/Codea/Talk/discussion/855/ludum-dare-with-codea-and-loeve-codify Tue, 17 Apr 2012 04:38:54 -0400 juaxix 855@/Codea/Talk/discussions Hello my loved coders :) I would like to introduce you to the Ludum Dare #23 — April 20th-23rd, 2012 — 10 Year Anniversary! ( http://www.ludumdare.com/ ) , I have just sign up and I think this is a great opportunity for Codea to be known and for us also, I would like to have Löve Codify ported and updated to let people play the games we could create those days of intense world competition, but I dont know the current status of the project... me myself created since the beginning some of my games in just one or two days, i think it is totally affordable, so... Go for it!!

]]>
Tiny World Space - Source Code - Ludum Dare #23 http://www.twolivesleft.com/Codea/Talk/discussion/996/tiny-world-space-source-code-ludum-dare-23 Sun, 13 May 2012 14:17:58 -0400 juaxix 996@/Codea/Talk/discussions Here is the source for the game: https://gist.github.com/2689533 and the videos:

and

]]>
Where should I start? http://www.twolivesleft.com/Codea/Talk/discussion/994/where-should-i-starts Sun, 13 May 2012 11:35:05 -0400 Nicbit 994@/Codea/Talk/discussions Hi, I'm new around here. I am a game programmer (usually program my games in c++ and OpenGL.) I was wondering what tutorials you would recommend for someone who knows c++ (tried the wiki tutorials but the links were broken.)
Thanks!

]]>
Blocks MapLoader http://www.twolivesleft.com/Codea/Talk/discussion/995/blocks-maploader Sun, 13 May 2012 11:35:15 -0400 Juanjo56 995@/Codea/Talk/discussions Hi Here it is my function MapLoader
is to load maps very much fast and it's easy to learn MapLoader and the main example



function setup()     displayMode(FULLSCREEN)     mapa = {{9,9,9,9,9,10,9,9,9,9,9},{9,9,9,9,9,10,9,9,9,9,9},{9,9,9,9,9,10,9,9,9,9,9},{9,9,9,9,9,10,9,9,9,9,9},{9,9,9,9,9,10,9,9,9,9,9},{300},{300},{300},{300},{300},{300}}     O = {vec3(20,180,280),vec3(20,210,230),vec3(20,190,180),vec3(28,400,400)} end function draw()     MapLoader(mapa,O,vec3(0, 138, 255)) end
]]>
Question about getn http://www.twolivesleft.com/Codea/Talk/discussion/992/question-about-getn Sun, 13 May 2012 02:49:56 -0400 pepinganos 992@/Codea/Talk/discussions Hello to everybody. I bought Codea a few days ago and I am enjoying it very much. Congrats to its creators, and please, keep improving it, I'm sure it will become a great development tool.

I have a question regarding getn. I need to know the size of a table, but I think getn is not working as expected, according to the Lua manual:

a={}
a[13] = 25
a[6] = 37
print(table.getn(a)) 

This program prints 0, as if the table were empty. Is it normal?

]]>
Codea Brush http://www.twolivesleft.com/Codea/Talk/discussion/603/codea-brush Thu, 02 Feb 2012 08:52:03 -0500 Simeon 603@/Codea/Talk/discussions I thought this was really cool. @Grant, a friend and colleague of mine made this while learning Codea. And painted the picture in it:

Codea Brush Pro

]]>
Question about the Network API in Codea 1.4 http://www.twolivesleft.com/Codea/Talk/discussion/990/question-about-the-network-api-in-codea-1.4 Sat, 12 May 2012 20:18:58 -0400 Deamos 990@/Codea/Talk/discussions Just got a quick question for the guys beta testing 1.4 or TLL.

Will the new HTTP GET API leave the possibility for doing JSON or XML Parsing from some external website? I know the actual parsing will have to written using existing functions, but I am more curious on how HTML data will be stored within a variable or class.

Thanks ahead

]]>
Question about modding codea http://www.twolivesleft.com/Codea/Talk/discussion/991/question-about-modding-codea Sat, 12 May 2012 23:33:11 -0400 KMEB 991@/Codea/Talk/discussions My iPad is jailbroken, so I can directly modify apps. There are several changes I want to make that would be fairily simple to do- for example, adding the ^ to the math tab, shrinking the size of the project display So that i can see me all at once, making it so that pressing return after typing end tabs one less than before, yadda yadda... Stuff that would be incredibly easy to do, but....

Many apps have hidden checks to see if they have been modded, and nuke emselves if they have been. I am aware that if I mess up the program through my own modification it is my own fault, but will the app actively punish me for any changes whatsoever?

I hope to get an answer soon,just adding a few customizations to the editor keys, like move line up and down, would speed my workflow up tremendously....

]]>
I/o file reading http://www.twolivesleft.com/Codea/Talk/discussion/983/i-o-file-reading Fri, 11 May 2012 23:20:16 -0400 Menlojin 983@/Codea/Talk/discussions Is it possible to do I/O ? As in reading individual presentation slides?

]]>
External Keyboard Shortcuts http://www.twolivesleft.com/Codea/Talk/discussion/993/external-keyboard-shortcuts Sun, 13 May 2012 04:11:51 -0400 shrike 993@/Codea/Talk/discussions I've tried to attach an usb keyboard at home and, even if typing text is obviously faster, a lot (the most) of things need to be done touching the screen. It would be nice to have some external keyboard shortcuts (predefined or even better user defined), using for example combination of shift, alt, ctrl and function keys, to fast access documentation, "play", color picker, texture picker, select one of the suggested code completition item, ecc.

]]>
Water FX http://www.twolivesleft.com/Codea/Talk/discussion/950/water-fx Sun, 06 May 2012 01:41:53 -0400 Connorbot999 950@/Codea/Talk/discussions Code:

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

tileSize = WIDTH/24
noiseScale = 1/5
noisePos = vec2(0,0)
noiseSpeed = 0.2

function setup()
    parameter("noiseScale", 1/30, 1, 1/5)    
    parameter("noiseSpeed", 0.05, 1, 0.2)

    tiles = {}
    for x = 1, WIDTH/tileSize do
        tiles[x] = {}
        for y = 1, HEIGHT/tileSize do
            tiles[x][y] = noise(x * noiseScale, y * noiseScale)
        end
    end
end

function moveNoise()
    for x,column in ipairs(tiles) do
        for y,value in ipairs(column) do
            tiles[x][y] = noise(x * noiseScale + noisePos.x, y * noiseScale + noisePos.y)
        end
    end
end

function draw()
    background(0, 164, 255, 255)
    
    for x,column in ipairs(tiles) do
        for y,value in ipairs(column) do
            fill((value+1)*0.5*255,100)
            rect((x-1)*tileSize, (y-1)*tileSize, tileSize, tileSize)
        end
    end
    
    noisePos = noisePos + vec2(0.5,0.3) * noiseSpeed
    moveNoise()
end

]]>
LUA Windows Based Editor http://www.twolivesleft.com/Codea/Talk/discussion/975/lua-windows-based-editor Thu, 10 May 2012 09:15:01 -0400 Munkie 975@/Codea/Talk/discussions I know this might be sacrilege, but...

Does anyone develop for Codea using a windows LUA editor? If so, which one do you use, and further how do you ensure the syntax for Codea is enforced while programming in LUA on Windows?

Thanks much, Munkie

]]>
Meshes in Cargo-Bot http://www.twolivesleft.com/Codea/Talk/discussion/981/meshes-in-cargo-bot Fri, 11 May 2012 09:40:50 -0400 mrspeaker 981@/Codea/Talk/discussions I was having a look at the source of Cargo-Bot and I noticed that the sprite() method is never used, but rather everything is managed by the Screen object instance that draws to (a pool of?) meshes.

Is that because it's super fast, or something? Cargo-Bot doesn't even have a huge number of sprites, so should we all be using meshes rather than sprites...

Actually, I guess my real question is: what is a mesh?!

]]>
Dropbox news http://www.twolivesleft.com/Codea/Talk/discussion/987/dropbox-news Sat, 12 May 2012 08:23:38 -0400 Doffer 987@/Codea/Talk/discussions It seems that Apple may allow Dropbox integration after all: http://www.appleinsider.com/articles/12/05/11/dropbox_fixes_app_rejection_issue_complies_with_apples_rules.html

]]>
Spriyt shearing online http://www.twolivesleft.com/Codea/Talk/discussion/954/spriyt-shearing-online Sun, 06 May 2012 04:48:28 -0400 Connorbot999 954@/Codea/Talk/discussions Mach a big box of senser's

To sense coller

And print sumfing lick the

Folwing code:

             !:......::!!*                  
         :................:!!*              
      :.....................::!*o           
    !.........................:!*oe      
   :...........................:!*oo        
  :............................:!!*oe       
 :.............................::!**oe      
!:.............................::!**oee     
!:.............................:!!*ooee     
!:............................:!!**ooee     
*!:.........................::!!**ooeee     
*!::.......................::!!**oooeee
o*!!::..................:::!!!**oooeeee 
 o**!!:::............::::!!!**oooeeeee  
  oo**!!!!::::::::::!!!!!***ooooeeeee    
   eooo****!!!!!!!!!*****ooooeeeeeee     
    eeeooooo*******oooooooeeeeeeeee         
      eeeeeeoooooooooeeeeeeeeeeee       
         eeeeeeeeeeeeeeeeeeeee 
             eeeeeeeeeeeee

(is a sercoll wive a shader)

(not mine :( )

Export it as a online scoreboard

And then decode it

I need hallp coding it [-O<

]]>
codea runtime template - memory stuff and calling objective c classes from lua http://www.twolivesleft.com/Codea/Talk/discussion/986/codea-runtime-template-memory-stuff-and-calling-objective-c-classes-from-lua Sat, 12 May 2012 07:02:11 -0400 muccio 986@/Codea/Talk/discussions First of all congratulations! Your work is really fresh and seems a great 'time-saving' engine for most of ios development. I'm considering to use it for developing quickly an app with realtime generated graphic, but before starting I would like to ask a couple of question:

  1. I read the maximum instructions stuff and from a first look to the parser code it seems the app load in memory all the lua scripting stuff and then execute everything, should this lead to memory leaks if the app is going to be big?

  2. By modifying the parser, it should be possible to call native code? I mean, if I need (i.e.) facebook integration, should be possible to set hooks and pass stuff to functions outside the lua code?

]]>
Goto vs. Return http://www.twolivesleft.com/Codea/Talk/discussion/969/goto-vs.-return Tue, 08 May 2012 14:47:37 -0400 Munkie 969@/Codea/Talk/discussions Again, I am definitely a newbie to Codea/LUA, and in my research and failed attempts I am trying to figure out how to return based on a conditional to a prior line.

What I am trying to do:


function Example() a = math.random(10) If a = 1 then goto Example()

Or in the days of coding with line numbers


10 Label1 20 a = int(rnd*10)+1 30 If a = 1 then goto 10

I am sure there is an easy solution, but I am having a hard time figuring this one out.

Thanks, Munkie

]]>
Set Mesh Rect invisible http://www.twolivesleft.com/Codea/Talk/discussion/985/set-mesh-rect-invisible Sat, 12 May 2012 02:37:50 -0400 shrike 985@/Codea/Talk/discussions Having no way to detatch an unused rect from a mesh, what's the best way to set a rect invisible? to collapse it's vertex or to set them to alpha 0?

]]>