Corona SDK error on lines 172 and 218, no filename, only question marks - error-handling

Corona SDK simulator, version 2013.1137 (2013.6.7) is displaying the following error:
Corona Simulator Runtime error
File: ?
Attempt to perform arithmetic on field '?' (a function value)
stack traceback:
[C]: ?
?: in function <?:172>
?: in function <?:218>
The error is caused by the following code (main.lua):
local d1 = display.newCircle(0, 40, 10)
local gNonEmpty1 = display.newGroup()
gNonEmpty1:insert(display.newCircle(0, 70, 10))
local gEmpty1 = display.newGroup()
transition.to(d1, { time = 1000, x = 100 })
transition.to(gNonEmpty1, { time = 1000, x = 100 })
transition.to(gEmpty1, { time = 1000, x = 100 })
local d2 = display.newCircle(0, 150, 10)
local gNonEmpty2 = display.newGroup()
gNonEmpty2:insert(display.newCircle(0, 180, 10))
local gEmpty2 = display.newGroup()
transition.to(d2, { time = 1000, x = 100, transition = easing.outExpo })
transition.to(gNonEmpty2, { time = 1000, x = 100, transition = easing.outExpo })
transition.to(gEmpty2, { time = 1000, x = 100, transition = easing.outExpo })
local d3 = display.newCircle(0, 260, 10)
local gNonEmpty3 = display.newGroup()
gNonEmpty3:insert(display.newCircle(0, 290, 10))
local gEmpty3 = display.newGroup()
transition.to(d3, { time = 1000, x = 100, easing.outExpo })
transition.to(gNonEmpty3, { time = 1000, x = 100, easing.outExpo })
transition.to(gEmpty3, { time = 1000, x = 100, easing.outExpo })
The actual line causing the error is the second to last one:
transition.to(gNonEmpty3, { time = 1000, x = 100, easing.outExpo })
You can check it out by commenting it.
Corona documentation states that:
You should have at least one DisplayObject inserted into a
Display Group before you change or read any of the properties
of the group (e.g., x, y, setReferencePoint(), etc.).
Hence, it would be legit to expect some weird behavior when using transition.to
on gEmpty1, gEmpty2 or gEmpty3. As expected, the first two blocks of transition.to, for a total of six calls, behave the same, except for the easing
which is the default, easing.linear, for the first three calls, and easing.outExpo for the other three calls.
If you make a mistake in writing the transition.to calls, and you write something similar to the last three transition.to calls, where the transition = part is missing in the specification of the easing function, the surprising thing is that only the one that targets the non-empty group, gNonEmpty3 is responsible for the incomprehensible error message.
Questions
What should you do in Corona SDK when you get an error with no line numbers and no file names, but only question marks?
Why Corona SDK is not able to provide meaningful reporting beside two line numbers, 172 and 218?
Why this error is occurring? My theory is that the transition.to doesn't perform much error checking; if you target an empty group the error in specifying the easing function will go unnoticed; probably this is related with the fact empty groups properties should not be used, so maybe transition.to or its internal update callback finds out that the group is empty and simply returns without doing anything. Instead, for the non-empty group, the missing transition = causes some code to be triggered not necessarily the easing code, and in that code the actual error occurs.
config.lua
application = {
content = {
width = 320,
height = 480,
scale = "letterBox",
fps = 30
}
}
Original Post (obsolete)
I'm having a hard time at tracking down an error in Corona SDK.
The error causes the simulator to show the following message:
Corona Simulator Runtime error
File: ?
Attempt to perform arithmetic on field '?' (a function value)
stack traceback:
[C]: ?
?: in function <?:172>
?: in function <?:218>
How shall I interpret such message? I have no source files with
that many lines, by the way.
I have a file named Button.lua and line 41 seems to be involved
in raising an exception, although it is not raised from that
line. The line is:
button:insert(b1)
I wrapped that line between two prints:
print("Before", button, b1)
button:insert(b1)
print("After")
The following messages are printed in the simulator console:
Corona Simulator[9801:f03] Before table: 0x11daf4aa0 table: 0x1152363a0
Corona Simulator[9801:f03] After

Instead of your line:
transition.to(gNonEmpty3, { time = 1000, x = 100, easing.outExpo })
use :
transition.to(gNonEmpty3, { time = 1000, x = 100, transition = easing.outExpo })
In corona, such error message will occur when you have some wrong syntax or wrong logic. So, check for those issues first. Inserting print between the lines (that you used) is the best solution to find such error lines.
Keep Coding............. :)

Related

Pine Script: " Can't call 'security' inside: 'if', 'for' "

because I cant find any way to test my Pine Script strategy on multiple symbols, I created a way to loop through my whole Script.
In This I made 10 variables for 10 different Symbols like this:
ersteTicker = "AAPL"
zweiteTicker = "MSFT"
dritterTicker = "..."
Than I loopedfrom 1 to 10 and made 10 If-querys, which give me in every loop the right symbol like this:
a = 1
for i = 0 to 10
if a == 1
tickerID = ersteTicker
if a == 2
tickerID = .....
Now I thougt everything should be all right, but now the console gives back an error message called:
line 75: Can't call 'security' inside: 'if', 'for'
Does anybody know how to bypass this problem??
best regards
Christian
P.S.: I already tested a small other script and in this script the console doesn't give me back this error message, even if I also made a for loop with a security function in it..
(looks like this)
//#version=3
strategy("Meine Strategie", overlay=true)
tickerID = "ADS"
vergleichstimeframe = "D"
TaesRSLPeriode = 200
a = 1
myEma() => ema(close, TaesRSLPeriode)
for i = 0 to 10
if ( a == 1)
Daily_ema = security(tickerID, vergleichstimeframe, myEma())
//plot(Daily_ema*TagesRSLGrenzwert)
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
Here's an example of global security. The security must not be inside of neither for nor if statements. If you need more symbols - use more securities. But bear in mind, that you can't choose a symbol from a set of symbols and call security with that symbol (because it'll be mutable variable and you cannot use them with security):
//#version=3
strategy("Meine Strategie", overlay=true)
tickerID = "ADS"
vergleichstimeframe = "D"
TaesRSLPeriode = 200
a = 1
myEma() => ema(close, TaesRSLPeriode)
// this always must stay global
Daily_ema = security(tickerID, vergleichstimeframe, myEma())
// here you could put more secureties:
//Daily_ema1 = security(tickerID1, vergleichstimeframe, myEma())
//Daily_ema2 = security(tickerID2, vergleichstimeframe, myEma())
//Daily_ema3 = security(tickerID3, vergleichstimeframe, myEma())
// ...
for i = 0 to 10
if a == 1
if Daily_ema > Daily_ema[i] // actual using of the security's result
strategy.entry("My Long Entry Id", strategy.long)
In general and according to previous comments, the strategy tester isn’t accurate. Just view an indication for the operation. Maybe the only benefit of the testing strategy is to determine the value of (SL, TP). Meanwhile the strategy depends on trusted intermittent periods, you can increase the SL 10 to avoid the temporary reflections

Createjs. Line follow element fiddle

I created this jsfiddle.
A line i connecting two elements, and I want the line to stay connected to both elements no matter where they go.
I've sort of succeeded, but with one pretty obvious error. It keeps drawing new lines instead of redrawing the existing line. Please help me on how to make it update the line position instead.
var stage = new createjs.Stage("canvas");
createjs.Ticker.setFPS(60);
createjs.Ticker.addEventListener("tick", tick);
var arrDots = [];
var arrLines = [];
var circle1 = new createjs.Shape().set({
x: stage.canvas.width/2,
y: 50,
cursor: "pointer",
name:"target"
});
circle1.graphics.f(createjs.Graphics.getRGB(Math.random()*0xFFFFFF))
.dc(0,0,20);
stage.addChild(circle1);
arrDots.push(circle1);
var circle2 = new createjs.Shape().set({
x: stage.canvas.width/2,
y: stage.canvas.height - 50,
cursor: "pointer",
name:"target"
});
circle2.graphics.f(createjs.Graphics.getRGB(Math.random()*0xFFFFFF))
.dc(0,0,20);
stage.addChild(circle2);
arrDots.push(circle2);
var line = new createjs.Shape().set({
graphics: new createjs.Graphics().s("#00f").mt(arrDots[0].x,
arrDots[0].y).lt(arrDots[1].x, arrDots[1].y)
});
stage.addChild(line);
arrLines.push([arrDots[0], arrDots[1], line]);
createjs.Tween.get(circle1, {loop: true}).to({x:50},
3000).to({x:stage.canvas.width/2}, 3000);
function tick(event) {
keepLineConnection();
stage.update();
}
function keepLineConnection() {
for(var i = 0; i < arrLines.length; i++) {
arrLines[i][2].graphics.mt(arrLines[i][0].x, arrLines[i][0].y).lt(arrLines[i][1].x, arrLines[i][1].y);
}
}
The reason it keeps drawing is because you keep adding commmands to the graphics. Basically, you are doing this:
graphics.mt().lt().mt().lt().mt().lt().mt().etc();
Since you are just adding new instrucitons, they will pile up over time,
and will eventually kill your processor.
An easy fix for that is to clear the graphics first before adding new ones:
graphics.clear().mt().lt();
A better approach is to use commands. Since EaselJS 0.7.0, all graphics commands are objects, and at any time you can update properties of those objects directly. For example, the MoveTo and LineTo commands both have an x and y property. Here is more info on Commands: http://blog.createjs.com/update-width-height-in-easeljs/
Here is a modified fiddle that stores of commands on the line, and then updates them on tick. I also made a few other updates, such as changing the timing mode to RAF, which is smoother than using interval-based timers at 60FPS.
https://jsfiddle.net/tck7x8u2/
// Store commands:
line.cmd1 = line.graphics.mt(0,0).command;
line.cmd2 = line.graphics.lt(0,0).command;
// Update commands:
var instr = arrLines[i],
line = instr[2];
line.cmd1.x = instr[0].x;
line.cmd1.y = instr[0].y;
line.cmd2.x = instr[1].x;
line.cmd2.y = instr[1].y;
Cheers!
Edit: Here is are some demos using that idea that I made a while back:
https://lab.gskinner.com/connections
http://jsfiddle.net/lannymcnie/2xoL08bx/
http://jsfiddle.net/lannymcnie/6rh7P/

Linqpad extension to plot graphs

I tried to plot some graphs in Linqpad with with "Util.RawHtml()" and "Dump()" but it is not working with this example from amcharts.com. I created a string variable including all the HTML source code but the result is not working.
string html = "";
using (System.Net.WebClient client = new System.Net.WebClient ())
{
html = client.DownloadString(#"http://pastebin.com/raw/pmMMwXhm");
}
Util.RawHtml(html).Dump();
Later versions of LinqPad 5 now support charting out of the box with Util.Chart. You can see the samples in the Samples Tab (next to My Queries) under
LINQPad Tutorial&Reference
Scratchpad Features
Charting with Chart
The following script is the Chart() - dual scale sample:
// Each y-series can have a different series type, and can be assigned to the secondary y-axis scale on the right.
var customers = new[]
{
new { Name = "John", TotalOrders = 1000, PendingOrders = 50, CanceledOrders = 20 },
new { Name = "Mary", TotalOrders = 1300, PendingOrders = 70, CanceledOrders = 25 },
new { Name = "Sara", TotalOrders = 1400, PendingOrders = 60, CanceledOrders = 17 },
};
customers.Chart (c => c.Name)
.AddYSeries (c => c.TotalOrders, Util.SeriesType.Spline, "Total")
.AddYSeries (c => c.PendingOrders, Util.SeriesType.Column, "Pending", useSecondaryYAxis:true)
.AddYSeries (c => c.CanceledOrders, Util.SeriesType.Column, "Cancelled", useSecondaryYAxis:true)
.Dump();
As I understand it, this will not work because the html contains scripts that will not be executed.
As an alternative, you can still use the old (and deprecated) google charts api, eg
var link = #"http://chart.apis.google.com/chart?chxt=y&chbh=a&chs=300x225&cht=bvg&chco=A2C180,3D7930&chd=t:10,20,30,40,50,60|30,35,40,45,55,60&chtt=Sample";
Util.Image (link).Dump();
or see
http://blog.divebomb.org/2012/11/dumping-charts-in-linqpad/
Not sure if it's the answer you're after but there may be value in looking at the DisplayWebPage method on the Util class in Linqpad. This correctly rendered your chart in the result window, (although there was a script error). Obviously, this may not solve your underlying issue.
I used version 5.10.00 to test this.

KineticJS won't draw a dashed line in Internet Explorer 10

Trying to display a dashed line with KineticJS (v4.7.3). It works fine in Chrome, but in IE (v10), a normal solid line is displayed.
Here's the code:
var element = document.getElementById('target'),
stage = new Kinetic.Stage({
container: element,
width: element.offsetWidth,
height: element.offsetHeight
}),
layer = new Kinetic.Layer();
layer.add(new Kinetic.Line({
points: [10, 10, 190, 190],
stroke: 'black',
strokeWidth: 1,
dashArray: [5, 4]
}));
stage.add(layer);
And you can see the behavior for yourself in here.
Fixed in IE-11 !
Until all "bad" IE's die, you can "do-it-yourself" fairly easily for lines (less easily for curves).
You can use a custom Kinetic.Shape which gives you access to a canvas context (a wrapped context).
Code is taken from this SO post: dotted stroke in <canvas>
var CP = window.CanvasRenderingContext2D && CanvasRenderingContext2D.prototype;
if (CP && CP.lineTo){
CP.dashedLine = function(x,y,x2,y2,dashArray){
if (!dashArray) dashArray=[10,5];
if (dashLength==0) dashLength = 0.001; // Hack for Safari
var dashCount = dashArray.length;
this.moveTo(x, y);
var dx = (x2-x), dy = (y2-y);
var slope = dx ? dy/dx : 1e15;
var distRemaining = Math.sqrt( dx*dx + dy*dy );
var dashIndex=0, draw=true;
while (distRemaining>=0.1){
var dashLength = dashArray[dashIndex++%dashCount];
if (dashLength > distRemaining) dashLength = distRemaining;
var xStep = Math.sqrt( dashLength*dashLength / (1 + slope*slope) );
if (dx<0) xStep = -xStep;
x += xStep
y += slope*xStep;
this[draw ? 'lineTo' : 'moveTo'](x,y);
distRemaining -= dashLength;
draw = !draw;
}
}
}
Totally off-topic: Go Wisconsin! I spent many a great summer at my grandmothers house in
Lacrosse.
Short answer: Not supported.
Via a thread here, the creator of KineticJS addresses this issue:
"[T]he dashArray property now uses the browser-implemented dashArray
property of the canvas context, according to the w3c spec. Firefox is
a little behind at the moment."
If you follow the thread, you'll discover that this was an issue for Firefox at one point, too, but that has been resolved. However, support for IE should apparently not be expected any time soon.

How to set axis margin in WinRT XAML Toolkit line chart?

Answer
Finally I solved my answer with this.
((LineSeries)MyChart.Series[0]).IndependentAxis = new LinearAxis
{
Minimum = 1,
Maximum = 5,
Orientation = AxisOrientation.X,
Interval = 1,
Margin = new Thickness(10, 0, 10, 0)
};
((LineSeries)MyChart.Series[0]).Clip = null;
((LineSeries)MyChart.Series[0]).Margin = new Thickness(10, 0, 10, 0);
I am drawing line chart with help of WinRT XAML Toolkit. I am setting X axis manually, but when I set I am getting wierd start & end point. I tried to set margin and padding but it's not working. Will you please suggest me how can I do that ?
((LineSeries)MyChart.Series[0]).IndependentAxis = new LinearAxis
{
Minimum = 1,
Maximum = 5,
Orientation = AxisOrientation.X,
Interval = 1,
//Margin = .... Not working
//Padding = .... Not working
};
I'd use a visual tree debugger to walk up the visual tree from these data points to see where the Clip property is set. In fact I just did that on the samples project and it is set on the LineSeries. See if it's set as part of its XAML template or if it is done in C# and remove it there. Also you could change the Minimum/Maximum values on your X axis to make more space. I'll add cleaning this all up to my TODO list.