# Agents.jl -- how to return the pos of an agent in Continuous space

**URL:** https://discourse.julialang.org/t/agents-jl-how-to-return-the-pos-of-an-agent-in-continuous-space/121305
**Category:** New to Julia
**Created:** [October 14, 2024, 7:52pm UTC](https://discourse.julialang.org/t/agents-jl-how-to-return-the-pos-of-an-agent-in-continuous-space/121305 "2024-10-14T19:52:51Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pogikano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pogikano/32/212353_2.png) [@pogikano](https://discourse.julialang.org/u/pogikano)
#### Post date: [October 14, 2024, 7:52pm UTC](https://discourse.julialang.org/t/agents-jl-how-to-return-the-pos-of-an-agent-in-continuous-space/121305/1 "2024-10-14T19:52:51Z")

</div>

I want to implement various custom agent moves. I need to obtain the x and y positions of an agent, and then update them. For example, this does not work:  
‘’’  
function agent\_step!(fish, model)  
xAdd = rand( -1:1 )  
yAdd = rand( -1:1 )  
fish.pos( (fish.pos.x + xAdd), (fish.pos.y + yAdd) )  
move\_agent!(fish, model, fish.pos)  
end  
‘’’  
How should I correct this?

---

<div class="post-metadata">

### Author: ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)
#### Post date: [October 14, 2024, 9:20pm UTC](https://discourse.julialang.org/t/agents-jl-how-to-return-the-pos-of-an-agent-in-continuous-space/121305/2 "2024-10-14T21:20:26Z")

</div>

You should show the error message for questions like these, and you should give runnable code.

Just use `move_agent!` and pass the new position.

```julia
julia> using Agents
julia> @agent struct Fish(ContinuousAgent{2,Float64}) end

julia> model = StandardABM(Fish);

julia> fish = Fish(1, SVector(0.0, 0.0), SVector(-1.0, -1.0));

julia> move_agent!(fish, SVector(1.0, 1.0), model) # to a set pos
Fish(1, [1.0, 1.0], [-1.0, -1.0])

julia> dx, dy = rand(-1:1), rand(-1:1);

julia> move_agent!(fish, fish.pos + SVector(dx, dy), model) # shift
Fish(1, [0.0, 2.0], [-1.0, -1.0])

```

---

<div class="post-metadata">

### Author: ![pogikano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pogikano/32/212353_2.png) [@pogikano](https://discourse.julialang.org/u/pogikano)
#### Post date: [October 16, 2024, 1:15am UTC](https://discourse.julialang.org/t/agents-jl-how-to-return-the-pos-of-an-agent-in-continuous-space/121305/3 "2024-10-16T01:15:38Z")

</div>

Ah! Adding SVectors! That makes sense. The error had to do with trying to access elements in an SVector. Your solution gets around this nicely. Many thanks!
