### Author Topic: Hello! (I also need help with some code)  (Read 3548 times)

#### Ravenplucker

• Bot Neophyte
• Posts: 3
##### Hello! (I also need help with some code)
« on: May 16, 2012, 05:30:44 AM »
Hey guys. I've just started messing around with Darwinbots, and am trying to add some random behaviour.  I can't figure out why this code doesn't work. I want it to randomly spin to the left and right. Anyone willing to lend a hand?

' Behaviour determination
cond
1 1 =            ' always true (easier way to do it...?)
start
50 rnd 150 store       ' Generates number between 0-50 every cycle and stores it in *150
stop

cond
*150 10 =         ' if *150 = 10
start
*151 10 store        ' then *151 = 10
stop

cond
*150 11  =         ' if *150 = 11
start
*151 11 store        ' then *151 = 11
stop

'Gene 2
'Spinning

cond
*151 10 =         ' if *151 = 10
start
300 .aimdx store       ' rotate 300-somethings to the right
stop

cond
*151 11 =         ' if *151 = 11
start
300 .aimsx store       ' rotate 300 somethings to the left
stop

end

I don't think this subforum has been posted in for awhile, but hopefully there's someone who can help me out.

#### Numsgil

• Bot God
• Posts: 7742
##### Re: Hello! (I also need help with some code)
« Reply #1 on: May 16, 2012, 01:24:10 PM »
Looks like you have the 'store' syntax backwards and a bit wrong

You want 10 151 store, for instance.  That stores '10' in to memory location '151'.

Remember that *151 is what lives in memory location 151.  So if you do 10 *151 store, you're actually saying that you should store '10' in to whatever memory location is pointed to by *151 (which isn't actually memory location 151 in all probability).

#### Ravenplucker

• Bot Neophyte
• Posts: 3
##### Re: Hello! (I also need help with some code)
« Reply #2 on: May 16, 2012, 10:14:48 PM »
I'm not sure I understand. Would you be able to rewrite a section of the code to show what you mean?

#### Numsgil

• Bot God
• Posts: 7742
##### Re: Hello! (I also need help with some code)
« Reply #3 on: May 17, 2012, 04:20:49 PM »
Try this:

Code: [Select]
`' Behaviour determinationcond 1 1 = ' always true (easier way to do it...?)start 50 rnd 150 store ' Generates number between 0-50 every cycle and stores it in *150 stopcond *150 10 = ' if *150 = 10start 10 151 store  ' then *151 = 10stopcond *150 11  = ' if *150 = 11start 11 151 store  ' then *151 = 11stop'Gene 2'Spinningcond *151 10 = ' if *151 = 10start 300 .aimdx store ' rotate 300-somethings to the rightstopcond *151 11 = ' if *151 = 11start 300 .aimsx store ' rotate 300 somethings to the leftstopend`

#### Ravenplucker

• Bot Neophyte
• Posts: 3
##### Re: Hello! (I also need help with some code)
« Reply #4 on: May 18, 2012, 08:57:59 PM »
It works perfectly!

Thanks.

#### havingphun

• Bot Builder
• Posts: 54
##### Re: Hello! (I also need help with some code)
« Reply #5 on: May 25, 2012, 04:23:06 PM »
Hi Ravenplucker. Don't I know you from the algodoo forums?