abs problems

Recommended Posts

yep

i am having problems with this, it should change the negative numbers to positive, but for some reason, it keeps them negative

i cant see any problems by myself so i decided to ask from here, since these are actually helpfull forums

i got this same code to work on c++ but not on autoit :/ [ofcourse, not exactly same, converted to c++ from autoit]

anyone got tips where i am going wrong?

EDIT:

X, Y is destination if you wonder what they are.

```Do
Send("{w down}")
\$x = abs(\$x)
\$y = abs(\$y)
\$xss1 = \$xss
\$yss1 = \$yss
\$dx = \$x - \$xss
\$dy = \$y - \$yss
\$dx = StringLeft(\$dx, 4)
\$dy = StringLeft(\$dy, 4)
\$distance = sqrt(\$dx^2 + \$dy^2)
Until  \$dx < 4 & \$dy < 4
send("{W UP}")```

Pythogorean theorem, ftw!.. if anyone noticed

Edited by zutto

Share on other sites

I have no idea where \$x and \$y are being assigned, but I have added Msgbox code to Monitor the variables, run it and see...

```Do
Send("{w down}")
Msgbox(0, "X and Y Values", "\$x=" & \$x & @CRLF & "\$y=" & \$y)
\$x = abs(\$x)
\$y = abs(\$y)
Msgbox(0, "X and Y Values", "\$x=" & \$x & @CRLF & "\$y=" & \$y)
\$xss1 = \$xss
\$yss1 = \$yss
\$dx = \$x - \$xss
\$dy = \$y - \$yss
\$dx = StringLeft(\$dx, 4)
\$dy = StringLeft(\$dy, 4)
\$distance = sqrt(\$dx^2 + \$dy^2)
Until  \$dx < 4 & \$dy < 4
send("{W UP}")```

Share on other sites

I have no idea where \$x and \$y are being assigned, but I have added Msgbox code to Monitor the variables, run it and see...

```Do
Send("{w down}")
Msgbox(0, "X and Y Values", "\$x=" & \$x & @CRLF & "\$y=" & \$y)
\$x = abs(\$x)
\$y = abs(\$y)
Msgbox(0, "X and Y Values", "\$x=" & \$x & @CRLF & "\$y=" & \$y)
\$xss1 = \$xss
\$yss1 = \$yss
\$dx = \$x - \$xss
\$dy = \$y - \$yss
\$dx = StringLeft(\$dx, 4)
\$dy = StringLeft(\$dy, 4)
\$distance = sqrt(\$dx^2 + \$dy^2)
Until  \$dx < 4 & \$dy < 4
send("{W UP}")```

\$x & \$y is assigned on the function..

i call the function with \$x & y.. but i try with MSGboxes

edit: abs fails :/

Edited by zutto

Share on other sites

Abs() of nothing will result in nothing.

You need to assign something to \$x and \$y before attempting an Abs on them.

\$x & \$y is assigned on the function..

i call the function with \$x & y.. but i try with MSGboxes

edit: abs fails :/

Share on other sites

\$x & \$y is assigned on the function..

i call the function with \$x & y.. but i try with MSGboxes

edit: abs fails :/

Fails with what input? What did the MsgBox() show? You can't expect help with a supposedly failing function without explaining what inputs it received.

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share on other sites

Fails with what input? What did the MsgBox() show? You can't expect help with a supposedly failing function without explaining what inputs it received.

it gave me the numbers as they we're.. as negative ;/

but yeah, i'll use other way

if \$number > 0 then \$number * -1

should do the job

Share on other sites

you abs(\$x)

you read (\$xss) raw from memory and subtract it from \$x

its your \$x - \$xss (if \$xss is > \$s you will get a negative in \$x)

This is obviously waypoint bot code, and you are moving towards the waypoint, what game you writing a bot for?

Share on other sites

you abs(\$x)

you read (\$xss) raw from memory and subtract it from \$x

its your \$x - \$xss (if \$xss is > \$s you will get a negative in \$x)

This is obviously waypoint bot code, and you are moving towards the waypoint, what game you writing a bot for?

good good, someone found out its for bot.. pythogorean theorem is kinda obvious tho..

trying to find out where it fails..

this is for wow.. :|

Share on other sites

it gave me the numbers as they we're.. as negative ;/

but yeah, i'll use other way

if \$number > 0 then \$number * -1

should do the job

Abs() works fine, but yours would have to be: if \$number < 0 then \$number * -1

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share on other sites

Abs() works fine, but yours would have to be: if \$number < 0 then \$number * -1

yeah <

but got everything to work now, my pathing system is succesful now

ty to everyone.

Share on other sites

```\$dx = \$x - \$xss
\$dy = \$y - \$yss
\$dx = StringLeft(\$dx, 4)
\$dy = StringLeft(\$dy, 4```

That leads me to believe that you are working with both numbers and strings... Perhaps that's where your problem is.

Create an account

Register a new account