Timer with 0.1 increment

malukorj

  • Posts: 22
Error:


Behavior: Timer
Source File: Design_7_7_Timer.mm
Line: 58
Reason: request for member 'toFixed' in '*(float*)(((char*)self) + OBJC_IVAR_$_Design_7_7_Timer._Time)', which is of non-class type 'float'

captaincomic

  • *
  • Posts: 6109
Okay, the code is written in AS3 and will not work on iOS.

For iOS you will need to try it with nev's and Sunflower's suggestions.

hansbe

  • Posts: 262
Ah, I don't do iOS  :-\

Goggling the topic i suspect you can put something like this in the code field :

[NSstring stringWithFormat@"%.1f",_Time]

but i can't tell you for sure ...

Also, I don't think nevs and sunflowers suggestions have anything to do with the conversion of the floating point presentation to a string representation of the number.

« Last Edit: May 17, 2012, 08:47:45 am by hansbe »

malukorj

  • Posts: 22
Any of this ideas is working.
I still searching on google how to do that on Objective-C.

http://en.wikipedia.org/wiki/IEEE_754-2008

http://forums.macrumors.com/archive/index.php/t-1098938.html

But no luck yet.

Sunflower

  • Posts: 591
Oh well, could it be that iOS handles floats worse than Flash? O.o'

Quote
Also, I don't think nevs and sunflowers suggestions have anything to do with the conversion of the floating point presentation to a string representation of the number.
No, not at all, my suggestion just shows the workaround which avoids the whole floating point problem at all. O.o'

First of all, make the timer increment by 1 rather than 0.1. Then, make a text attribute "Draw time" or something like that - this is what you will draw.

Now, for the logic inside timer block:
Code: [Select]
do every [0.1] seconds
  increment [Timer] by [1]
  set Draw Time to [[ floor of [[Timer]/10] ] + [ . ] [ remainder of [Timer]/10 ]]
The blocks inside Draw Time setter are the text adders, not number ones. So if you have value of Timer 1346, it'll be like "134" + "." + "6" = "134.6".

Then in "draw text" block replace the Timer (which is now 10x larger) with Draw Time
And if it *still* produces weird results (which would practically mean that floating point representation of *integers* is poor as well O.o), apply the "round" function to remainder of Timer! ^^'

malukorj

  • Posts: 22
Something like that ? I think I made something wrong.

Error:
Behavior: Timer
Source File: Design_7_7_Timer.mm
Line: 51
Reason: invalid conversion from 'int' to 'NSString*'

hansbe

  • Posts: 262
It is basically correct, but you should check that these things are in order:
  • [Draw Time] should be a Text attribute
  • You should use the [text + text] adding block when adding
  • You'll need another [text + text] block for the '.'

malukorj

  • Posts: 22
Same error

Behavior: Timer
Source File: Design_7_7_Timer.mm
Line: 51
Reason: invalid conversion from 'int' to 'NSString*'

hansbe

  • Posts: 262
.. this works in flash, so i guess it's a bug that with the iOS code generation that it does not work with only code blocks.

You could try to wrap the [floor of ...] and [remainder of ...] blocks in [anything as text] blocks.

malukorj

  • Posts: 22
.. this works in flash, so i guess it's a bug that with the iOS code generation that it does not work with only code blocks.

You could try to wrap the [floor of ...] and [remainder of ...] blocks in [anything as text] blocks.

FINALLY!!
That works for iOS, with [anything as text] blocks, but a remove the other block, I'm using just one without ["."] + ["time" / 10 as text].

Check the attachment.

Hope that post are going to help a lot for other users.

Thanks hansbe for the help!

nev, captaincomic and Sunflower, thanks all.

tavocello

  • Posts: 2
I´ve figured out a waaaaay faster and more efficient way of doing it!
Just split the timer into two attributes (seconds and decimals), adding "1" instead of "0.1" and drawing all of it in three consecutive text fields [Attribute for Seconds], [. (dot)] and [Attribute for Decimals], check the decimals everytime so they are never bigger than 99. (SCREENSHOTS ATTACHED)
Fully working timer! You can adjust it to have as many decimals as you desire!

You´re welcome! ;D