Darwinbots Forum

Welcome To Darwinbots => Newbie => Topic started by: Ravenplucker on May 16, 2012, 05:30:44 AM

Title: Hello! (I also need help with some code)
Post by: Ravenplucker 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.
Title: Re: Hello! (I also need help with some code)
Post by: Numsgil 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).
Title: Re: Hello! (I also need help with some code)
Post by: Ravenplucker 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?
Title: Re: Hello! (I also need help with some code)
Post by: Numsgil on May 17, 2012, 04:20:49 PM
Try this:

Code: [Select]
' 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
 10 151 store  ' then *151 = 10
stop


cond
 *150 11  = ' if *150 = 11
start
 11 151 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
Title: Re: Hello! (I also need help with some code)
Post by: Ravenplucker on May 18, 2012, 08:57:59 PM
It works perfectly!

Thanks.  :D
Title: Re: Hello! (I also need help with some code)
Post by: havingphun on May 25, 2012, 04:23:06 PM
Hi Ravenplucker. Don't I know you from the algodoo forums?