Ajuda no break

Tire suas dúvidas sobre programação em AutoHotkey

Moderator: Gio

theon
Posts: 124
Joined: 23 Jun 2019, 15:39

Ajuda no break

04 Mar 2022, 16:16

Galera boa noite, estou tentando por um break mais nao estou conseguindo.
quando o if targert > 0 ele da break e continuar de onde parou tem como ?

Code: Select all

loop{

if (target = 0){
   if (cave=1) 
   If (t = 0)

x=%house_pos_x1%
y=%house_pos_y1%
GuiControl,, andando, 1
t:= 1
gosub, show_it ;~1
}
if (target = 0) {

  if (cave2 = 1) 
  If (t = 1)


x= %house_pos_x2%
y= %house_pos_y2%
GuiControl,, andando, 2
t:= 2
gosub, show_it ;~2
}
if (target = 0){
  if (cave3 = 1)
  If (t = 2)


x= %house_pos_x3%
y= %house_pos_y3%
GuiControl,, andando, 3
t:= 3

gosub, show_it ;~3
}
if (target = 0){
  if (cave4 = 1)
  If (t = 3)


x= %house_pos_x4%
y= %house_pos_y4%
GuiControl,, andando, 4
t:= 4

gosub, show_it ;~4
}
if (target = 0){
  if (cave5 = 1)
  If (t = 4)


x= %house_pos_x5%
y= %house_pos_y5%
GuiControl,, andando, 5
t:= 5

gosub, show_it ;~5
}

if (target = 0){
  if (cave6 = 1)
  If (t = 5)


x= %house_pos_x6%
y= %house_pos_y6%
GuiControl,, andando, 6
t:= 6

gosub, show_it ;~6
}

if (target = 0){
  if (cave7 = 1)
  If (t = 6)


x= %house_pos_x7%
y= %house_pos_y7%
GuiControl,, andando, 7
t:= 7
gosub, show_it ;~7

}

if (target = 0){
  if (cave8 = 1)
  If (t = 7)


x= %house_pos_x8%
y= %house_pos_y8%
GuiControl,, andando, 8
t:= 0

gosub, show_it ;~8
}
}}}
return
show_it:
{
	 posx := mem.write(addressmana + 0x154 ,x, "int")
     posy := mem.write(addressmana + 0x15c ,y, "int")
	 settimer, clicar, 300
	 sleep, 400
	 settimer, clicar, off
  Sleep, %tempo%
  }
return
User avatar
Gio
Posts: 1248
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: Ajuda no break

04 Mar 2022, 17:07

Boa tarde Theon.

O Break interrompe completamente um loop, então se a execução chegar em uma linha de break, ela vai pular pra próxima linha após o loop inteiro e continuar dali.

Outra opção seria o Continue, que permite que você encerre apenas a iteração atual do loop (ou seja, ele vai voltar pra primeira linha do loop e continuar dali adicionado 1 ao contador de iterações).

Para onde você quer que a execução vá quando a condição target > 0 for atingida?

Além disso vejo que você colocou várias condicionais subsequentes idênticas if (target = 0) dentro do loop. Creio que isso não seja necessário.

:arrow: Supondo que você queira que o loop fique testando a variável target e que faça alguma coisa quando ela tiver valor 0, você poderia escrever assim:

Code: Select all

loop
{
	if (target = 0)
	{
		if (cave=1) AND (t = 0)
		{
			x=%house_pos_x1%
			y=%house_pos_y1%
			GuiControl,, andando, 1
			t:= 1
			gosub, show_it ;~1
		}
		
		if ((cave2 = 1) AND (t = 1))
		{
			x= %house_pos_x2%
			y= %house_pos_y2%
			GuiControl,, andando, 2
			t:= 2
			gosub, show_it ;~2
		}
		
		if ((cave3 = 1) AND (t = 2))
		{
			x= %house_pos_x3%
			y= %house_pos_y3%
			GuiControl,, andando, 3
			t:= 3
			gosub, show_it ;~3
		}	
		
		if ((cave4 = 1) AND (t = 3))
		{
			x= %house_pos_x4%
			y= %house_pos_y4%
			GuiControl,, andando, 4
			t:= 4
			gosub, show_it ;~4
		}
		
		if ((cave5 = 1) AND (t = 4))
		{
			x= %house_pos_x5%
			y= %house_pos_y5%
			GuiControl,, andando, 5
			t:= 5
			gosub, show_it ;~5
		}
		
		if ((cave6 = 1) AND (t = 5))
		{
			x= %house_pos_x6%
			y= %house_pos_y6%
			GuiControl,, andando, 6
			t:= 6
			gosub, show_it ;~6
		}
		
		if ((cave7 = 1) AND (t = 6))
		{
			x= %house_pos_x7%
			y= %house_pos_y7%
			GuiControl,, andando, 7
			t:= 7
			gosub, show_it ;~7
		}
		
		if ((cave8 = 1) AND (t = 7))
		{
			x= %house_pos_x8%
			y= %house_pos_y8%
			GuiControl,, andando, 8
			t:= 0
			gosub, show_it ;~8
		}
	}
}

return
show_it:
{
	posx := mem.write(addressmana + 0x154 ,x, "int")
	posy := mem.write(addressmana + 0x15c ,y, "int")
	settimer, clicar, 300
	sleep, 400
	settimer, clicar, off
	Sleep, %tempo%
}
return

PS: Não sou muito fan de One True Brace, então tive que reescrever para poder ler melhor :roll:
theon
Posts: 124
Joined: 23 Jun 2019, 15:39

Re: Ajuda no break

08 Mar 2022, 05:36

@Gio , desculpa a demora tive uns problemas com hd, olha como ficou meu codigo, eu queria q quando no if target se ele checar e nao poder ir ele volte para o if target
explo : ele ta o if t= 0 ele fez uma checagem e nao conseguiu ir por t=1 ele volta pra o t =0 ate o if targert = 0 de ok.

Code: Select all

loop{

if (target = 0)
{ ; pos 1
   if (cave=1) 
   {
   If (t = 0)
   {
    If (go = 1)
   {
sleep, 1000
x=%house_pos_x1%
y=%house_pos_y1%
GuiControl,, andando, 1
t:= 1

gosub, show_it ;~1
}}}}
if (target = 0) ; pos 2
{
  if (cave2 = 1) 
  {
  If (t = 1)
{
    If (go = 1)
   {
sleep, 1000
x= %house_pos_x2%
y= %house_pos_y2%
GuiControl,, andando, 2
t:= 2
gosub, show_it ;~2
}}}}
if (target = 0)
{ ; pos 3
  if (cave3 = 1)
  {
  If (t = 2)
{
    If (go = 1)
   {
sleep, 1000
x= %house_pos_x3%
y= %house_pos_y3%
GuiControl,, andando, 3
t:= 3

gosub, show_it ;~3
}}}}
if (target = 0)
{ ; pos 4
  if (cave4 = 1)
  {
  If (t = 3)
{
    If (go = 1)
   {
sleep, 1000
x= %house_pos_x4%
y= %house_pos_y4%
GuiControl,, andando, 4
t:= 4

gosub, show_it ;~4
}}}}
if (target = 0)
{ ; pos 5
  if (cave5 = 1)
  {
  If (t = 4)
{
    If (go = 1)
   {
sleep, 1000
x= %house_pos_x5%
y= %house_pos_y5%
GuiControl,, andando, 5
t:= 5

gosub, show_it ;~5
}}}}

if (target = 0)
{ ; pos 6
  if (cave6 = 1)
  {
  If (t = 5)
{
    If (go = 1)
   {
sleep, 1000
x= %house_pos_x6%
y= %house_pos_y6%
GuiControl,, andando, 6
t:= 6

gosub, show_it ;~6
}}}}

if (target = 0)
{ ; pos 7
  if (cave7 = 1)
  {
  If (t = 6)
{
    If (go = 1)
   {
sleep, 1000
x= %house_pos_x7%
y= %house_pos_y7%
GuiControl,, andando, 7
t:= 7
gosub, show_it ;~7

}}}}

if (target = 0)
{ ; pos 8
  if (cave8 = 1)
  {
  If (t = 7)
{
    If (go = 1)
   {
sleep, 1000
x= %house_pos_x8%
y= %house_pos_y8%
GuiControl,, andando, 8
t:= 0

gosub, show_it ;~8
}}}}
sleep, 1000
}
return

show_it:

{

	 posx := mem.write(addressmana + 0x154 ,x, "int")
     posy := mem.write(addressmana + 0x15c ,y, "int")
	 settimer, clicar, 300
	 sleep, 400
	 settimer, clicar, off
  Sleep, %tempo%
  }
return

clicar:

CoordMode, Pixel, Window
PixelSearch,px,py,X_Pos,Y_Pos,cx2,cy2, 0x0000FF, 5, Fast RGB
If ((errorLevel = 0) AND (target = 0) AND (go = 1) )
loop,1 
{
sleep, 300


py := py+4
px := px+1

ControlClick, x%px% y%py%, LDPlayer,, Left, 1, NA
sleep, 300
 c := 1
}
return

Return to “Ajuda e Suporte Geral”

Who is online

Users browsing this forum: No registered users and 8 guests