Progress bar with actor count? *SOLVED*

Non-platform specific questions.

Progress bar with actor count? *SOLVED*

Postby Hblade » Wed May 01, 2013 12:44 am

I'd like to make a progress bar for my tile editor =) (When first opening) I got this but it's not working :(
Code: Select all
int i, i2=(1+ActorCount("Tiles")), i3=i2/10000;
setpen(0, 0, 255, 0, 1);
for(i=0;i<i3;i++)
{
    moveto(i, 0);
    lineto(i, height);
}


Anybody have a working way of doing this? ^^ Prettymuch theres 100x100 tiles max, and I tried to take the ol' HP bad method but its not working quite like I thought lol, normally dividing something by a higher number would result in a decimal thus finding the percentage, but idk how the heck something with a high number like this would work :P

EDIT:
Found it =D I had to do Witdh* i2/i3 :D Example:
int i, i2=width*(1+ActorCount("Tiles")), i3=i2/10000;
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Progress bar with actor count? *SOLVED*

Postby lcl » Wed May 01, 2013 6:02 pm

Hblade wrote:normally dividing something by a higher number would result in a decimal thus finding the percentage

Dividing by just some random higher number doesn't give you percentage, it gives a random small number.
You have to divide with the maximum value. That way when the process is complete the math goes like 10000/10000 = 1, which is same as 100%

The correct formula of calculating percentages is as follows.
The needed numbers:

v (for value) - is the current value
maximum - is the maximum value, in this case the value of actors to be created

The formula:

Code: Select all
percentage = v/maximum;


Since v is always smaller or equal to max, the result will always be between 0 - 1, so it presents the
v's percentage of max.

Now, for a progress bar, you'd want to draw that percentage of the canvas actors width, so you'd multiply it's width by the percentage for getting the
x position to draw to. Like this:

Code: Select all
int i;
double percentage = (ActorCount("Tiles") / 10000);

setpen(0, 0, 255, 0, 1);

for (i = 0; i < height; i ++)
{
    moveto(0, i);
    lineto(width * percentage, i);
}
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Progress bar with actor count? *SOLVED*

Postby Hblade » Wed May 01, 2013 6:30 pm

Thanks lcl but I already got it =) I'll take note of this though!
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Progress bar with actor count? *SOLVED*

Postby lcl » Wed May 01, 2013 7:08 pm

Hblade wrote:Thanks lcl but I already got it =) I'll take note of this though!

I know, I just wanted to tell you, since you seemed not to know too much about percentages. :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Progress bar with actor count? *SOLVED*

Postby Hblade » Wed May 01, 2013 7:37 pm

Thanks ^^
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron