Subsection in functions

So my code is this

var bob={
var jim=createSprite(200,200);
function movejim(plart) {
function draw() {

The console log display that bob.bab is equal to jim but jim will not move, is there a way to achieve something similar to what im trying to do?
This is on by the way since thats why my teacher wants me to use, here is a link to it Game Lab -

I am not sure I understand — do you want to move the variable jim? The one defined as var jim = createSprite(200, 200)?
That’s not the same thing as the string "jim".
If you want to have the sprite inside the object you need to add it inside the object, something like bob.bab = createSprite(200, 200)

My goal here is to move jim using a function and a subsection so if i ever needed a different sprite to move insted of jim, like for example if i had var barry=createSprite(200,200), I would be able to do bob.bab=“berry” and my function would still work.

No, it wouldn’t. A string and a variable are two different things.

If you have the variable jim you can’t reference it with the string "jim", that’s not how coding works.
movejim will work if you movejim(jim)

If you want to have the sprite in the object you need to

var jim = createSprite(200, 200);

var bob = {
  bab: jim


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.