Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,209 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
while loops and moving imprecisions. #311883
02/22/10 01:15
02/22/10 01:15
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline OP
Serious User

Joined: Jul 2004
Posts: 1,710
Hello.

Imagine i want to slide a panel down to the y=200 on the screen. from y=0;

i do it: while(panel.pos_y<200){
panel.pos_y+=1*time_step;
wait(1);
}

But sometimes, i check that the final y its not 200, but 199 or something depending on the lag..

How can i avoid that? without the time_step, it gets shaky or slides very quickly.


check this little example with dynamic progress bar...
And you will se that after a while the panels will overlay, showing a one pixel overlay...
Open C file

Last edited by MMike; 02/22/10 02:36.
Re: while loops and moving imprecisions. [Re: MMike] #311893
02/22/10 02:33
02/22/10 02:33
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Originally Posted By: MMike
Hello.

Imagine i want to slide a panel down to the y=200 on the screen. from y=0;

i do it: while(panel.pos_y<200){
panel.pos_y+=1*time_step;
wait(1);
}

But sometimes, i check that the final y its not 200, but 199 or something depending on the lag..

How can i avoid that? without the time_step it gets shaky or slides very quickly.


It is very unlikely that panel.pos_y is precisely 200 after the loop. Example:

- panel.pos_y is 199.873

- assume that time_step was 0.527 in the last frame

- next iteration:

while(panel.pos_y<200){
panel.pos_y+=1*time_step;
wait(1);
}

- panel.pos_y is now 200.4 -> end of loop

I hope you know what time_step does/ is/ how it is calculated. Otherwise have a look at the manual.

Solution:

while(panel.pos_y<200){
panel.pos_y+=1*time_step;
wait(1);
}
panel.pos_y = 200;



"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: while loops and moving imprecisions. [Re: Superku] #311895
02/22/10 02:38
02/22/10 02:38
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline OP
Serious User

Joined: Jul 2004
Posts: 1,710
Oh superku thats super! though the correction to panel=200 will sometimes be seen, as the panel moves up a little bit, and thats not desireble.. the solution would be using integer maybe?

Re: while loops and moving imprecisions. [Re: MMike] #311897
02/22/10 02:41
02/22/10 02:41
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
while(panel.pos_y<200){
panel.pos_y+=1*time_step;
panel.pos_y = minv(panel.pos_y,200);
wait(1);
}

Integer should work, too.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: while loops and moving imprecisions. [Re: MMike] #311898
02/22/10 02:47
02/22/10 02:47
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline OP
Serious User

Joined: Jul 2004
Posts: 1,710
using my example.. and without the time_step to make 199.87 values..
i use this:

Sql Query:
//animate progress bar, from 0 to target value:
while(level_fact<1){
pbar.s_graph_r.scale_x=integer(pbar.value*level_fact);  //---->>> increase the scale of the repeating bmap piece of pixel width =1 to scale the needed target
pbar.s_graph_cr.pos_x=pbar.s_graph_cl.pos_x+7 //after the start cap piece of 6 pixels plus 1, so its next seamless
 + ( pbar.s_graph_r.scale_x)/2 //DONT KNOW WHY IT NEEDS TO BE /2 or /0.5 ?? but wihout this.. it wont work correct?
  ; pbar.s_graph_cr.pos_y=pbar.s_graph_cl.pos_y;
level_fact+=0.1;
wait(10 ); //somewhat slow...
}



but it stills overlay at later.. what im missing?

Last edited by MMike; 02/22/10 02:50.
Re: while loops and moving imprecisions. [Re: MMike] #311899
02/22/10 02:51
02/22/10 02:51
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline OP
Serious User

Joined: Jul 2004
Posts: 1,710
maybe the scaling is giving incorrect pixel sizes on screen, though the number of the scale is corrected displayed

when i scale up something that is 1pixel on _x , and scaling to 2 , i think it will means 2 pixels ...

when scaling to 50, it will means 50 pixels.. and so on too 100..

although the problem on the start is not showing.. only when the scale reaches (probably 70)

Last edited by MMike; 02/22/10 02:55.
Re: while loops and moving imprecisions. [Re: MMike] #311901
02/22/10 03:00
02/22/10 03:00
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Why don't you use:

while(panel.pos_y<200){
panel.pos_y+=1*time_step;
panel.pos_y = minv(panel.pos_y,200);
wait(1);
}

?


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: while loops and moving imprecisions. [Re: Superku] #312011
02/22/10 19:39
02/22/10 19:39
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline OP
Serious User

Joined: Jul 2004
Posts: 1,710
because the example i need more, is more complex than that? did you check it on the top of the post there is a file to download.

Re: while loops and moving imprecisions. [Re: MMike] #312057
02/23/10 00:37
02/23/10 00:37
Joined: Jul 2004
Posts: 1,710
MMike Offline OP
Serious User
MMike  Offline OP
Serious User

Joined: Jul 2004
Posts: 1,710
i tryed to use the reapeating method of scaling up size_x (that as the manual says will repeat the bmap, which in this case is 1 px lenght...
but what i get it a weird effect like spaced repeating bmap... (i think its not a bug)

and from the manual " The panel size is multiplied with the panel scale."

When i use size_x to move the cap panel on the end, to slide with the repeating one.. that size_x is constant..

So Manual is wrong?

Last edited by MMike; 02/23/10 00:41.
Re: while loops and moving imprecisions. [Re: MMike] #312141
02/23/10 13:40
02/23/10 13:40
Joined: Mar 2007
Posts: 112
MikeS Offline
Member
MikeS  Offline
Member

Joined: Mar 2007
Posts: 112
Hi.

To clear confusion about panel scale:

the panel scale is an multiplikator.

The original bmap which is shown on your screen does have scale 1

if you want it double big set scale to 2
if you want it half, set scale to 0.5

so the scale is only an factor.

An example, you have an bmap with 10 X10 pixels.

if you set its scale (scalex and scaley) to 2 it will be displayed with 20 x20 pixels(2 times the height and width of the original)
scale 3 = 30 x30 pixels (3 times the height and width of original)
scale 0.5 = 5 x 5 pixels (half the height and width of the original)

Hope that helps

Greetings

Mike

Page 1 of 2 1 2

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1