Jump to content

Ending Loop When found Pixel Color


 Share

Recommended Posts

Hello i Have HP Bar in my game and it has 170px of width and then im gonna find start of this by mouse pos then i got $hpStart[0] = 661  $hpStart[1] = 230 ,  $hpEnd[0] = 839

And there is from $hpStart[0] = 661 the same color - 0xCB423B but depends of my points of hp for example on pixel  $hpStart[0] = 745 would be another color not  0xCB423B and then i will know my my character got 50% of health points.

 

I encountered problem here - for loop still looping to 839 and not founding this change in color for example on pixel $hpStart[0] = 745

I would know actual $i counter and $hpEnd[0] then only i can calculate current health percent value 

 

Please help me how to achieve that! Thanks for any help

 

Func MouseCord()
    $MousePos = MouseGetPos()
    global $hpStart = $MousePos
    global $hpEnd = $hpStart
            $hpEnd[0] = $hpEnd[0] + 170
            
                For $i = $hpStart[0] To $hpEnd[0] ; Looping from 661 to 839
                        $pixel = PixelGetColor($i,$hpStart[1])
                            If $pixel <> 0xCB423B Then
                                $hpNowPer = ( $hpEnd[0] - $i ) / 170
                                $hpPoOdjeciu = 1 - $hpNowPer
                                $hpNowPercent = Round($hpPoOdjeciu,2)
                                ExitLoop ; - that not working
                            EndIf
                Next
 EndFunc

 

 

Link to comment
Share on other sites

  • Moderators

@Szmycu you come back after 24 hours off and immediately post again regarding a game. As you're obviously not interested in following the forum rules, we are not interested in your company.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...