Codea 3.0 (184)

@dave1707 - thanks for the feedback, not described my query very well.

In setup() say define

target = vec2(left+22,up+59)

The use target in draw(), are values calculated in setup and stored in target or is it the formula and the calcs are done for each draw() iteration.

Maybe setup() is a bad suggestion - what about global definitions in any other function?

Edit: I am getting flickering in print() actions when I use output.clear() and am trying to make sense of it.

@Bri_G The calculation is done in draw. You would have to vary the values of left and up in draw or a function called from draw. Then target would be calculated and you would use target.x and target.y to do whatever. As for the flicker with print, I think that’s caused because of the time it takes to clear the print area and the execution of the draw function. They’re probably not synced.

@Bri_G Are you thinking of something like def in basic where you can do something like def sum(x)=x+2x+3x+4*x and then s=sum(8) would give s a value of 80.

@dave1707 - not sure, not seen that before, but it does look to operate in a similar way to what I have described. What I’m trying to do is cut down time in the draw loop by reducing calculations. I’ll try my code by calculating the values before adding them to the table. Also I’ll add FPS to check on the load on the draw() function. I’ve hit another issue with the touch function that may be causing the problem.

@Bri_G If the values of your calculations are repetitive with time, then you can calculate them in setup and build a table. Then in draw you can read the values from the table. If they’re not repetitive, then there’s no point in putting them in a table and you just have to calculate them in draw. Try to make as many of your variables local, that will speed things up.

@Bri_G When you do pos = vec2(left+3,up+5) then lua uses the current values of left and up and stores the result of the calculation.

Although this is the opposite of what you’re trying to do, then for completeness to make a vector vary you would need to make it a function (which could itself be a method on an object). So you would have pos = function() return vec2(left+3,up+5) end, or you could make left and up parameters of the function.

This “calculate immediately” feature is quite useful when, say, swapping two variables: you can put x,y = y,x.

@LoopSpace - thanks for the feedback. What you describe is exactly what I suspected. What I was concerned about was that Lua places the formula, with current values of variables, into a table when set up in setup() (pardon the pun) and then recalculated whenever the variable is called from draw() or other functions.

I think you’ve answered my question in that the formula is held in the table and could be used as a variable in subsequent calculations. I need to carry out the formula initially and store just the values in the table. I mistakenly thought that within setup the calculations would be done and just the values stored.

Back to work . Thanks for the update.

In 176 the new editor should now be at feature parity with the old one. Please let me know if there are any issues. The plan is to release Codea with iPhone support (finally) starting with this version if there are no major issues.

@Simeon loaded version 176 via testflight-but crashes immediately on startup (ipad pro).

@piinthesky thanks for the quick report. Wonder if it’s an issue with building under the iOS 13 SDK and running on 12. Looking into it.

@Simeon Version 176. Same issue with me on an iPad Air. Loaded it twice and crashed both times.

I’m just sending out a fixed build. Sorry for the trouble!

This is fixed in 177. Sorry about the bug

@Simeon Version 177 now loads and runs OK.

@Simeon New editor. One thing that I miss is the arrow key that allowed me to move the cursor to the right. In the example below, after I would put the 2 in the [], I would use the arrow key to move the cursor past the ] where I would do = . I guess I have to get used to long pressing the space bar and then moving the cursor over.

function setup()
    tab={}
    tab[1]=123
    tab[2]
end

@simeon, 177 doesn’t crash, but my current project no longer runs…seems readLocalData no longer picks up the default value (second parameter) if the variable does not yet exist?

@Simeon New editor: readprojecttab isn’t working correctly. If you don’t specify a project it should read the tab in the current project. It currently gives an error.

If there is something in the very first line, auto complete doesn’t work. That might have been mentioned in a previous release.

Double tapping a word and selecting reference from the popup doesn’t work.

@Bri_G I’m a little confused. You write:

I mistakenly thought that within setup the calculations would be done and just the values stored.

but this is what I said does happen. Consider:

a = 3
b = a + 4
a = 5

At the end of this, a stores 5 and b stores 7. b does not “remember” that a was used in its definition and changing a has absolutely no effect on b at all.

The fact that you’re using vectors makes no difference to this.

@Bri_G Actually you can put the calculation in a table. It would probably be a whole lot slower using it. See the example.

function setup()
    left=5
    up=10

    tab={}
    tab[1]="target = vec2(left+22,up+59)"

    loadstring(tab[1])()

    print(target)
end

@dave1707 @piinthesky thanks for those reports, was your use of readProjectTab and readLocalData happening in the global scope? I.e., before setup() was run? I think I know what’s causing it and can fix