creatures caves welcome, guest
downloads   gallery   dev   community   creatchi   forum   mycaves
bookmarks | search | post new topic
Development Forum
old
Why isn't this code working?   
Ghosthande
Prodigal Sock

Ghosthande
United States  

 visit Ghosthande's website: Breeders Beware
  12/22/2009

Long story short--my critter isn't working right and I can't figure out why.

It's supposed to be a larva that loops an animation as it climbs a tree, then it pupates (changes its pose to a pupa) and creates an adult. Then kills itself.

For some reason, though, instead it only plays the animation once, goes to the pupa pose, then repeats the animation, goes to the pupa pose again, and so on. It repeats this process infinitely.

The basic animation and movement sequence is what is supposed to loop, but instead it only happens once. The whole sequence of climbing and then pupating is supposed to happen only once, but instead it loops! Why is this happening?


[edit] I've even tried taking out the loop thing and making it repeat using REPS and REPE instead, but it still repeats the whole segment. :(



subr tree
rnge 1000
esee 2 4 60663
doif targ ne null
setv va00 posx
seta va99 targ
targ ownr
seta ov99 va99
setv ov98 0

loop
doif va00 gt posx
fric 10
anim [0 0 0 1 1 1 2 2 2 3 3 3 4 4 4]
velo 2 0
over
fric 100
elif va00 lt posx
fric 10
anim [5 5 5 6 6 6 7 7 7 8 8 8 9 9 9]
velo -2 0
over
fric 100
endi


doif touc targ ov99 eq 1 or ov99 eq null
targ ownr
addv ov98 1
else
targ ov99
setv va00 posx
targ ownr
setv va01 va00
setv va02 va00

subv va01 posx

setv va03 posx
subv va02 va03

doif va01 lt 30 and va01 gt 0
addv ov98 1
elif va03 lt 30 and va03 gt 0
addv ov98 1
endi
endi
untl ov98 ge 5

velo 0 0

doif ov99 ne null
targ ov99
setv va76 posx
targ ownr
setv va77 va76
mvsf va77 posy

* if necessary, wait until this tree has grown up
targ ov99
setv va78 pose
targ ownr
setv va79 va78
doif va79 lt 5
loop
wait 10
targ ov99
doif targ ne null
setv va78 pose
targ ownr
setv va79 va78
endi
untl va79 eq 5
endi

* set your goals--how high do you climb?
targ ov99
setv va79 post
targ ownr
setv va80 va79
subv va80 rand 30 50

attr 64
accg -0.5

* if you're facing right
doif pose lt 5
loop
velo 0 -1
anim [15 16 17 18 19]
over
velo 0 0
untl va80 le posy
* if you're facing left
else
loop
accg 0
velo 0 -1
anim [10 11 12 13 14]
over
velo 0 0
untl va80 le posy
endi

attr 192
accg 1
* now pupate, mister!
pose rand 30 31
wait rand 400 500
lock
inst
setv va00 posx
setv va01 posy
new: simp 2 13 60662 "ng_ordinfly" 15 0 rand 500 4000
attr 192
accg 1
fric 100
perm 10
mvsf va00 va01
tick 1
targ ownr
unlk
kill ownr
else
wait rand 400 500
lock
inst
setv va00 posx
setv va01 posy
new: simp 2 13 60662 "ng_ordinfly" 15 0 rand 500 4000
attr 192
accg 1
fric 100
perm 10
mvsf va00 va01
tick 1
targ ownr
unlk
kill ownr
endi
else
targ ownr
gsub walk
endi
next
retn



 
Malkin

Malkin

Manager


 visit Malkin's website: Malkin's page at CWiki
  12/22/2009

Have you tried investigating the code of the C3 butterfly? That does roughly the same thing as what you're trying to do here.

My TCR Norns
 
Ghosthande
Prodigal Sock

Ghosthande


 visit Ghosthande's website: Breeders Beware
  12/22/2009

I know, but C3 .cos files are horrendously long, they don't tell you what anything does or what any of the variables mean--at least I have a code that works for the most part, and that I am already familiar with. The critter itself actually works quite well, it's just this particular climbing/pupating segment that isn't working.


 
AquaShee

AquaShee



  12/22/2009  1

I tried my best to read all that, but it was kinda hard to figure things out. Here's how I would've done it.

I always give my critters a "target" variable, usually ov99 or something.
When they are hungry, I run the subroutine to find food, and point ov99 at the food if it isn't already pointing at somethign tasty. When they want to mate, ov99 points at a mate, and so on.
This way, I can just check if my critter is targetting the right object, and if it is, I run a general approach subroutine. Moving towards a mate, piece of cheese or a toy all use the same approach routing.
If the target can be touched, I move on to the interaction.

The most useful part is that the timer script gets run through completely each time, without any unnecessary looping inside the script itself.
It just goes: Are you hungry? Have you found food? Are you near it? Take a step... Are you hungry?
The same way would work great for your bugs: Are you old enough to pupate? Have you found a tree? Are you near it? Take a step. Old enough? Found tree? Near it? Ok, climb up. Old enough? Found tree? Near it? Reached top yet? Ok, climb some more,... And so on.

The C3 butterflies (and most other agents in C3) work the same way. Otherwise the timer script would get interrupted and would have to start over if any other script got called.


The Community Scribble: make (y)our own metaroom!
 
Malkin

Malkin

Manager


 visit Malkin's website: Malkin's page at CWiki
  12/22/2009

Have you tried splitting up the subroutine, say by giving the pupate section its own subroutine?

My TCR Norns
 
Ghosthande
Prodigal Sock

Ghosthande


 visit Ghosthande's website: Breeders Beware
  12/22/2009

Not yet. I ought to, though.

The most useful part is that the timer script gets run through completely each time, without any unnecessary looping inside the script itself.



That's a good idea, I'll have to try that too. That's the strategy I used to make the Archie work.



[edit] Awesome, it's working now! :D
I broke it up into different stages and used variables to force it to go through each stage, pretty much as AquaShee described. Little larva hums and haws for a while but always does his stuff like he's supposed to.

Thank you both for your help! Now if nothing else goes seriously wrong maybe I can have this finished by Christmas after all...



 
Malkin

Malkin

Manager


 visit Malkin's website: Malkin's page at CWiki
  12/22/2009

Squee! :D

My TCR Norns
 
AquaShee

AquaShee



  12/23/2009

Woo! I'm glad to hear it works now. :D
I'm glad you understood what I meant to explain, it's a tricky concept. I had to learn it the hard way myself.
The Botanoid, for example, doesn't use this technique, it just waits and advances a pose running through the timer script just once. But when ettins pushed the 'plant', it always curled back into a seed because the Timer script just starts over.
This is why the Botanoid cannot be seen by creatures at the moment. I should update and re-release it.


The Community Scribble: make (y)our own metaroom!
 
Ghosthande
Prodigal Sock

Ghosthande


 visit Ghosthande's website: Breeders Beware
  12/23/2009

The silly thing is, I've actually used that strategy once before, for the Archie, but I totally forgot why I did it that way.


 
AquaShee

AquaShee



  12/23/2009

Because it works great, that's why! The Blackbird uses it too, as does the BSTL Machine. :D
Even better is that I can just copy subroutines between agents now because they are so useful. :D


The Community Scribble: make (y)our own metaroom!
 


downloads
cobs
adoptions
creaturelink
metarooms
breeds
 
gallery
art
wallpaper
screenshots
graphics
promos
sprites
dev
hack shack
script reservations
dev resources
active projects
dev forum
 
community
links
advice
chat
polls
resources
creatchi
 
forum
bookmarks
general
news
help
development
strangeo
survivor
mycaves
log in
register
lost pw
1 online
RisenAngel
creatures caves is your #1 resource for the creatures artificial life game series: creatures, creatures 2, creatures 3, docking station, and the upcoming creatures family.

contact    help    privacy policy    terms & conditions    rules    donate    wiki