How do I explain this inconsistency ?

Get help using Construct 2

Post » Wed May 03, 2017 2:26 pm

Message: Semoreh can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Hi there ! :D

I'm no big connoisseur in trigonometry but I had to dip into it a little in order to generate a laser for my Run N' Gun shooter. I've managed to have my laser working but I've been puzzled by one small inconsistency I can't explain...

(I've simplified the CapX and you can download it here : https://www.mediafire.com/?hbpi2gy8icdcjhc)
(to generate a laser you have to hold an arrow or more and use the left click)

See, I have a debug box. When I add into my debug box Cos(270) it writes 0 as expected. Also Sin(270) writes -1.
So that's good.
But when I try to concatenate Cos(270)&" / "&Sin(270) the cosinus is wrong. It gives a figure veeeeery small but not nul. So it writes something like "-1.8369701987210297e-16 // -1" instead of "0 // -1".

Is it because of the cosinus ?
Or because of the concatenation ?
More importantly, can this mess up my computation for the laser's width in any way ? (line 27-28 of the Event Sheet 1)

Thanks in advance for taking the time to reassure me :)
Best regards
Last edited by Semoreh on Wed May 03, 2017 2:40 pm, edited 1 time in total.
B
5
Posts: 12
Reputation: 258

Post » Wed May 03, 2017 2:35 pm

Why are you using strings for math?
Image ImageImage
B
168
S
50
G
164
Posts: 8,236
Reputation: 105,591

Post » Wed May 03, 2017 2:39 pm

What do you mean ?
I can usually concatenate figures without problem :?
B
5
Posts: 12
Reputation: 258

Post » Wed May 03, 2017 2:51 pm

Well to start it's an extra step to convert strings into numbers, and then there's bound to be issues with the conversion, which could vary widely between browsers.
Image ImageImage
B
168
S
50
G
164
Posts: 8,236
Reputation: 105,591

Post » Wed May 03, 2017 2:57 pm

I'm converting a number into a string, sure, but that doesn't explain why Cos(270°) becomes this weird number when it's not alone. 0 converted into a string should still be "0", right ?
Cos(270°) should always be strictly equal to zero... unless I don't understand cosinuses well (which is a possibility).
B
5
Posts: 12
Reputation: 258

Post » Wed May 03, 2017 3:27 pm

Could be 0, could be null.
It depends on the browser, and how it's setup to handle it.
Image ImageImage
B
168
S
50
G
164
Posts: 8,236
Reputation: 105,591

Post » Wed May 03, 2017 4:49 pm

That's the problem with floating point arithmetic. There's nothing you can do about it, you just have to deal with it. However, a number like -1.8369701987210297e-16 is so small that you won't ever notice anything visually... so you might as well consider it to be 0.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Wed May 03, 2017 5:19 pm

Yeah, the value is the real issue.
Sorry I'm just off on the strings.
That's like saying eggs+flour+milk+sugar=cookies
Image ImageImage
B
168
S
50
G
164
Posts: 8,236
Reputation: 105,591

Post » Wed May 03, 2017 7:08 pm

If you want to force the debug text to be more readable, I guess you could always do something like rounding the value to 5 or 6 decimals (or whatever number you deem significant).

example for 5 decimals :
Image

Smaller values will then always be equal to 0.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Wed May 03, 2017 7:37 pm

Oh, it's just text.
Well, nevermind all I said.
Image ImageImage
B
168
S
50
G
164
Posts: 8,236
Reputation: 105,591

Next

Return to How do I....?

Who is online

Users browsing this forum: Darth Crusher and 1 guest