Highlighted

[Beginner] Didgit declaration

Community Beginner ,
Jan 25, 2019

Copy link to clipboard

Copied

Hey

I just started programming and created a counter.

It only counts full digits tho (1,2,3..) - I want it to count in half didgits (0.5,1,1,5,2).

But it seems I have a problem with my declaration

Code:

-------------------------

var counter:uint;

function init():void{

counter = 0;

dicke.text = counter +" cm";

   

btn_pfeilhoch.buttonMode = true;

btn_pfeilhoch.addEventListener(MouseEvent.CLICK, on_press)}

function on_press(event:MouseEvent):void{

updatecounter()}

function updatecounter():void{

counter += 0.5 ;

dicke.text = counter +" cm"}

init();

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

You can use the Math.min function.

Instead of

counter += 0.5;

You can write:

counter = Math.min(counter + 0.5, 4);

Regards,

JC

Views

133

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

[Beginner] Didgit declaration

Community Beginner ,
Jan 25, 2019

Copy link to clipboard

Copied

Hey

I just started programming and created a counter.

It only counts full digits tho (1,2,3..) - I want it to count in half didgits (0.5,1,1,5,2).

But it seems I have a problem with my declaration

Code:

-------------------------

var counter:uint;

function init():void{

counter = 0;

dicke.text = counter +" cm";

   

btn_pfeilhoch.buttonMode = true;

btn_pfeilhoch.addEventListener(MouseEvent.CLICK, on_press)}

function on_press(event:MouseEvent):void{

updatecounter()}

function updatecounter():void{

counter += 0.5 ;

dicke.text = counter +" cm"}

init();

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

You can use the Math.min function.

Instead of

counter += 0.5;

You can write:

counter = Math.min(counter + 0.5, 4);

Regards,

JC

Views

134

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jan 25, 2019 0
Adobe Community Professional ,
Jan 25, 2019

Copy link to clipboard

Copied

Hi.

Your counter variable data type must be Number instead of uint because you need to store non-integers values.

I hope this helps.

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 25, 2019 1
Community Beginner ,
Jan 26, 2019

Copy link to clipboard

Copied

thanks guys   it worked perfectly fine!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 26, 2019 0
Community Beginner ,
Jan 26, 2019

Copy link to clipboard

Copied

another problem that I have right now is to min and max the counter:

I want it to go from 0 to 4 in 0.5 steps.

any suggestins

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 26, 2019 0
Advocate ,
Jan 25, 2019

Copy link to clipboard

Copied

Hi Lucas

JC is right. uint is an unsigned integer, a natural number (1,2,3 ..) which isn't signed with + or -, so it is always a positive, full number. It can be a floating point number like 1.5.

Just start your code with

var counter:Number;

..

Klaus

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 25, 2019 1
Community Beginner ,
Jan 26, 2019

Copy link to clipboard

Copied

another problem that I have right now is to min and max the counter:

I want it to go from 0 to 4 in 0.5 steps.

any suggestins

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 26, 2019 0
Adobe Community Professional ,
Jan 26, 2019

Copy link to clipboard

Copied

You can use the Math.min function.

Instead of

counter += 0.5;

You can write:

counter = Math.min(counter + 0.5, 4);

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 26, 2019 1
Community Beginner ,
Jan 26, 2019

Copy link to clipboard

Copied

you are a literal god

thank you so much...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 26, 2019 0
Community Beginner ,
Jan 26, 2019

Copy link to clipboard

Copied

the problem now tho is, when i trace it it traces fine from 0 to 4, but when I click down it doesnt trace 3.5--3--2.5....

it only traces 4

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 26, 2019 0
Community Beginner ,
Jan 26, 2019

Copy link to clipboard

Copied

ok solved.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jan 26, 2019 0