ID:2137396
 
(See the best response by Nadrew.)
Code:
mob
KEYDOWN(k) //Receives 'GamepadLeftAnalog XxY'
if(findtext(k,"GamepadLeftAnalog"))
var/a = findtext(k,"Analog")+6
var/b = findtext(k,"x")
var/X = text2num(copytext(k,a,b))
var/Y = text2num(copytext(k,b+1))
//world.log << "[a] :: [b] :: [X],[Y]"

if(X>0)step(src,EAST,round(X*step_size))
if(X<0)step(src,WEST,round(abs(X)*step_size))
if(Y>0)step(src,NORTH,round(Y*step_size))
if(Y<0)step(src,SOUTH,round(abs(Y)*step_size))


Problem description:

This movement is designed for the left gamepad analog stick. It works, but when values near 0, it gets really unexpected results like random super speed. Any suggestions?
Best response
When the values get low enough you might end up passing something low enough to step() that it thinks you're passing 0, which would trigger a move based on step_size. You could probably check the calculated values you end up passing to make sure they're always at least 1, because I believe step() will round the third argument.
In response to Nadrew
That was it, thanks.
You're also better off using the - operator instead of abs(), when you know X or Y are negative already. It'll always be faster, although in this proc that's not likely to make a real difference.
In response to Nadrew
With sub-pixel movement enabled, you can move using any values given by the analog inputs, at any speeds, including less than a whole pixel per tick. Pretty much no other game engine than BYOND rounds positions.

Also, why are you parsing text for this? It should be as simple as something like this:
// code for the player or player controller

var
tmp
move_analog_x
move_analog_y

verb
// macro command: move-analog-input [[x]] [[y]]
move_analog_input(X as num, Y as num)
set hidden = TRUE, instant = TRUE
move_analog_x = X
move_analog_y = Y

// something called every tick
Update()
var speed = GetSpeed()
if(speed && (move_analog_x || move_analog_y))
// sub-pixel enabled movement
Translate(
move_analog_x * speed,
move_analog_y * speed)