# Fixing old code and ran into SetObjective error

**URL:** <https://discourse.julialang.org/t/fixing-old-code-and-ran-into-setobjective-error/29377>\
**Category:** General Usage\
**Created:** [October 1, 2019, 6:41pm UTC](https://discourse.julialang.org/t/fixing-old-code-and-ran-into-setobjective-error/29377 "2019-10-01T18:41:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajimithing](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@ajimithing](https://discourse.julialang.org/u/ajimithing)\
**Post date:** [October 1, 2019, 6:41pm UTC](https://discourse.julialang.org/t/fixing-old-code-and-ran-into-setobjective-error/29377/1 "2019-10-01T18:41:22Z")

</div>

I am working through an old code, and having to change a bunch of stuff to work with the new JuMP package. (ex. replacing {} with (), replacing @DefVar with variable, replacing AddConstraint with constraint, etc.)

I’ve run into the following error when running the code:

**ERROR:** LoadError: LoadError: UndefVarError: @setObjective not defined

Here is the first line of the code with that wording:

# Objective

```
@setObjective(m, Max, sum{skaters[i,:Projection]*skaters_lineup[i], i=1:num_skaters} + sum{goalies[i,:Projection]*goalies_lineup[i], i=1:num_goalies})

```

Any help on what to change here?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [October 1, 2019, 7:36pm UTC](https://discourse.julialang.org/t/fixing-old-code-and-ran-into-setobjective-error/29377/2 "2019-10-01T19:36:19Z")

</div>

A very large number of things have changed if you are still using `@defVar`.

You should read the latest documentation: [Quick Start Guide · JuMP](http://www.juliaopt.org/JuMP.jl/v0.20.0/quickstart/)

---

<div class="post-metadata">

**Author:** ![ajimithing](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@ajimithing](https://discourse.julialang.org/u/ajimithing)\
**Post date:** [October 2, 2019, 1:24am UTC](https://discourse.julialang.org/t/fixing-old-code-and-ran-into-setobjective-error/29377/3 "2019-10-02T01:24:05Z")

</div>

Right, I’ve figured out most of the changes. I’m wondering if anyone can help with this particular one. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [October 2, 2019, 6:02am UTC](https://discourse.julialang.org/t/fixing-old-code-and-ran-into-setobjective-error/29377/4 "2019-10-02T06:02:26Z")

</div>

The page linked has `@objective`

---

<div class="post-metadata">

**Author:** ![ajimithing](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@ajimithing](https://discourse.julialang.org/u/ajimithing)\
**Post date:** [October 2, 2019, 10:17pm UTC](https://discourse.julialang.org/t/fixing-old-code-and-ran-into-setobjective-error/29377/5 "2019-10-02T22:17:13Z")

</div>

I am a complete newbie with Julia or any programming tbh. I downloaded a code a couple years ago, and have been using it forever. I got a new computer, downloaded Julia, then I discovered all of the changes that took effect with the new versions. I’ve been trying to rewrite the code with all of the new formatting, but have gotten stuck on this one line (in original post). I read through the page that was linked, but it looks like it is showing different commands to give to Julia - I am looking for what the new terminology is for @setObjective so I can edit the code. Hopefully what I’m saying makes sense. I appreciate you guys trying to help, but I’m looking for a more direct answer (if there is one, of course), as I’m not really familiar with the language used on that page that was linked.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [October 3, 2019, 1:31am UTC](https://discourse.julialang.org/t/fixing-old-code-and-ran-into-setobjective-error/29377/6 "2019-10-03T01:31:01Z")

</div>

Direct answer: change `@setObjective` to `@objective`.

Better answer: that’s unlikely to be the only problem you have. For example, `solve` is now `optimize!`, `getvalue` is now `value`, and all the solvers have changed, so `CbcSolver()` is no longer a thing. So, you should spend the time to read through the documentation. The QuickStart guide has most of what you’ll need.
