Jump to content

Progress Bar not showing ? why?


Recommended Posts

Okay guys, I am having some problems here, cant figure it out :S

So I want a progress bar when a player hits marker. that will go from 0 to 100% in 2 seconds :)

I have this:

Server Side:

  
if(isElementWithinMarker(keyPresser,marker1) then 
    triggerClientEvent(keyPresser, "showBar", keyPresser) 
end 
  

Client Side:

  
bar1 = guiCreateProgressBar ( 0.4, 0.5, 0.3, 0.1, true ) 
guiSetVisible(bar1,false) 
  
addEvent("showBar",true) 
function progressBar1() 
guiSetVisible(bar1,true) 
setTimer(setProgressBar, 50, 40, bar1, 1) 
setTimer(guiSetVisible,2000,1, bar1, false) 
end 
addEventHandler("showBar", getRootElement(), progressBar1) 
  
  

My problem is that the progress bar doenst appear on screen :/

And I have no errors on console :S

Thanks in advance guys ;)

Link to comment

Okay guys, I managed to do this, but the bar fills very fast, right when it gets visible, I made this for:

  
for x= 2.5, 100 do 
    setTimer(guiProgressBarSetProgress, 50, 1, bar1, x) 
end 
  

My idea was, 100/2.5 = 40.

So the for will run 40 times, and then 50 ms (of timer) * 40 times of for = 2000ms .. that is 2 seconds, like I want..

But its not working, when bar gets visible, it goes immediately 100% :S

Does some know the problem?

Thanks in advance.

Link to comment

well currently you create 98 (because you havent specified your step for incrementing, and default is +1, not 2.5) timers right away, they all run almost simultaneously.

that's why your bar fills so fast.

should be something like this:

guiProgressBarSetProgress(bar1, 0) 
setTimer(function() guiProgressBarSetProgress(bar1, guiProgressBarGetProgress(bar1)+2.5) end, 50, 40) 

Link to comment
well currently you create 98 (because you havent specified your step for incrementing, and default is +1, not 2.5) timers right away, they all run almost simultaneously.

that's why your bar fills so fast.

should be something like this:

guiProgressBarSetProgress(bar1, 0) 
setTimer(function() guiProgressBarSetProgress(bar1, guiProgressBarGetProgress(bar1)+2.5) end, 50, 40) 

Thanks for ur reply, before I read this, I tryed with:

  
setTimer(guiProgressBarSetProgress, 50, 40, bar1, guiProgressBarGetProgress(bar1) + 2.5) 
  

And it was freezing at 2.5%, and I think its the same?

Anyway I will try ur solution, thanks.

Link to comment
well currently you create 98 (because you havent specified your step for incrementing, and default is +1, not 2.5) timers right away, they all run almost simultaneously.

that's why your bar fills so fast.

should be something like this:

guiProgressBarSetProgress(bar1, 0) 
setTimer(function() guiProgressBarSetProgress(bar1, guiProgressBarGetProgress(bar1)+2.5) end, 50, 40) 

Thanks for ur reply, before I read this, I tryed with:

  
setTimer(guiProgressBarSetProgress, 50, 40, bar1, guiProgressBarGetProgress(bar1) + 2.5) 
  

And it was freezing at 2.5%, and I think its the same?

Anyway I will try ur solution, thanks.

EDIT: It worked, thanks Aibo!!

Link to comment
Thanks for ur reply, before I read this, I tryed with:
  
setTimer(guiProgressBarSetProgress, 50, 40, bar1, guiProgressBarGetProgress(bar1) + 2.5) 
  

And it was freezing at 2.5%, and I think its the same?

it was freezing at 2.5% because guiProgressBarGetProgress(bar1) + 2.5 is calculated only once, on timer initialization, so it sets progress to 2.5 all 40 times.

Link to comment
Thanks for ur reply, before I read this, I tryed with:
  
setTimer(guiProgressBarSetProgress, 50, 40, bar1, guiProgressBarGetProgress(bar1) + 2.5) 
  

And it was freezing at 2.5%, and I think its the same?

it was freezing at 2.5% because guiProgressBarGetProgress(bar1) + 2.5 is calculated only once, on timer initialization, so it sets progress to 2.5 all 40 times.

Ahh I see! Thanks, I understand now!

But look your solution, stops around 60~70% dont get to 100%, why?

Its suppose to fill it.. 2.5 * 40 = 100 :S

Thanks ;)

Link to comment
Ahh I see! Thanks, I understand now!

But look your solution, stops around 60~70% dont get to 100%, why?

Its suppose to fill it.. 2.5 * 40 = 100 :S

Thanks ;)

probably because 2.5 gets rounded to 2, so 40*2 is only 80.

you can try this, see if it helps:

guiProgressBarSetProgress(bar1, 0) 
setTimer(function() guiProgressBarSetProgress(bar1, guiProgressBarGetProgress(bar1)+4) end, 80, 25) 

Link to comment
Ahh I see! Thanks, I understand now!

But look your solution, stops around 60~70% dont get to 100%, why?

Its suppose to fill it.. 2.5 * 40 = 100 :S

Thanks ;)

probably because 2.5 gets rounded to 2, so 40*2 is only 80.

you can try this, see if it helps:

guiProgressBarSetProgress(bar1, 0) 
setTimer(function() guiProgressBarSetProgress(bar1, guiProgressBarGetProgress(bar1)+4) end, 80, 25) 

Thanks alot guys, it worked both ways!! JH10 way and Aibo way, but there is difference.

JH10 way: its exactly 2 seconds but the bar will fill 5% then 10% then 15% and so on..

Aibo way: its exactly 2,5 seconds but the bar will fill 2% then 4% then 6% and so on..

Thanks!!

By the way, only one more question here, its possible to set text inside the progress bar? and color to bar when full and color to bar thats empty?

THANKS

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...