Welcome To Darwinbots > Newbie
Hello! (I also need help with some code)
Ravenplucker:
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:
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:
I'm not sure I understand. Would you be able to rewrite a section of the code to show what you mean?
Numsgil:
Try this:
--- Code: ---' 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
--- End code ---
Ravenplucker:
It works perfectly!
Thanks. :D
Navigation
[0] Message Index
[#] Next page
Go to full version