Development Forum |
|
Savannahs11's Question Pile 1 | 2 | |
|
the1whoscreams
|
10/4/2017 | |
Grendel Man suggested it, so I now have one topic I'll ask all my programming questions in. Here goes the first one: How do I define what happens when a button on a compound agent is clicked? |
GimmeCat
|
10/4/2017 | |
When you create a button part on a compound agent, you use this command:
PAT: BUTT (command) part_id (integer) sprite_file (string) first_image (integer) image_count (integer) rel_x (decimal) rel_y (decimal) rel_plane (integer) anim_hover (byte-string) message_id (integer) option (integer) |
message_id is the message the button sends when it's clicked. So if you want to send an 'Activate 1' to the base agent, you'll do '1' here, then whatever you want to happen will be defined in that script.
On the other hand, you may want a totally user-defined behaviour that cannot be triggered by any other means, so you'd use a user-defined script number like '99' or something. Then you need to add that script, like 'scrp 2 0 0 20123 99' and it will get called when the button is clicked.
The variable _P1_ is set to the button's ID when clicked, meaning you can set up a switch case for multiple buttons on the agent even if they all call the same script. |
the1whoscreams
|
10/5/2017 | |
I'm trying to use a subroutine. CAOS Tool doesn't see anything wrong with my script, but when I inject the COS, I get an "unresolved label "[subroutine]" at token ''" error. Is there something I don't know about that you need to put in to have a subroutine function correctly?
EDIT: Wait, no. I figured that one out. |
Malkin
Manager
|
10/5/2017 | |
How did you figure it out? So that the rest of us know...
My TCR Norns |
the1whoscreams
|
10/5/2017 | |
I originally had the script define the subroutine near the install script, but moving it to the line after it was called fixed it. Also, another problem. When a button is pressed, the machine should open a weird hatch thing at the bottom, vend an object, then close said thing. Right now, it just opens and then sits there forever without actually vending anything.
scrp 3 3 14893 301
part 9
setv va00 posx
setv va01 posy
anim [0 1 2 3 4 5]
inst
new: simp 2 25 14895 "nichelingmother" 8 24 510
attr 194
elas 10
accg 2
perm 100
part 9
anim [5 4 3 2 1 0]
endm |
|
Malkin
Manager
|
10/5/2017 | |
Have you checked out the balloon maker tutorial?
My TCR Norns |
GimmeCat
|
10/5/2017 | |
Your vent script doesn't appear to place the vended object anywhere. It creates it, but doesn't position it anywhere. It might even be appearing behind the machine if they're fighting on the same z-axis. |
Fuzzy Dragonhat
Pilla
|
10/5/2017 | 1 |
You need to targ ownr again after the attributes of the vended object are set, right now it's trying to animate part 9 pf the vended object. (+what has been said above: position of the object that was vended has to be set too)
Visit my Creatures blog/website - Pilla's DS Agents
Join us on Discord - Caos Coding Cave
Visit/contribute to the Creatures Wiki |
the1whoscreams
|
10/5/2017 | |
I knew about moving the object, but I guess that bit got removed somewhere along the line while I was fiddling with the CAOS. Now, it vends, but not in the right spot, and I don't specifically need help with that part, but now, it's skipping the first part of its animation. |
GimmeCat
|
10/5/2017 | |
You'll have to post the updated code any time you make a change so that we can diagnose the problem. |
the1whoscreams
|
10/5/2017 | |
I'm at school now, and I can't access my code, but I'm pretty sure it's something like this:
scrp 3 3 14893 301
part 9
setv va00 posx
setv va01 posy
anim [0 1 2 3 4 5]
inst
new: simp 2 25 14895 "nichelingmother" 8 24 510
attr 194
elas 10
accg 2
perm 100
mvto va00 va01
targ ownr
part 9
anim [5 4 3 2 1 0]
|
|
Fuzzy Dragonhat
Pilla
|
10/5/2017 | 1 |
You have to put 'over' after the first animation, then the code resumes execution after the animation. Right now the first animation doesn't have any time to finish before the code gets to the second animation
Visit my Creatures blog/website - Pilla's DS Agents
Join us on Discord - Caos Coding Cave
Visit/contribute to the Creatures Wiki |
the1whoscreams
|
10/5/2017 | 1 |
Thanks, Pilla. I'll try that when I get home. |
the1whoscreams
|
10/5/2017 | |
That worked. I'm trying to get the button to animate when pressed now, but it throws an 'animation change failed' error.
scrp 3 3 14893 301
part 2
anim [0 7]
over
setv va00 posx
setv va01 posy
part 9
anim [0 1 2 3 4 5]
over
inst
new: simp 2 25 14895 "nichelingmother" 8 24 510
attr 194
elas 10
accg 2
perm 100
mvto va00 va01
targ ownr
part 9
anim [5 4 3 2 1 0]
endm |
|
Malkin
Manager
|
10/5/2017 | |
Maybe it's similar to 'pose change failed'?
The Common Errors list on the CDN has some information available on that.
My TCR Norns |
the1whoscreams
|
10/5/2017 | |
That didn't help. |
GimmeCat
|
10/5/2017 | |
Are you certain the sprite has 8 images for your 'anim [0 7]' to be valid? If you've added more images to the sprite during development, you might want to check that all in-use copies of the file have been properly updated and there aren't any old versions hanging around. |
the1whoscreams
|
10/5/2017 | |
It has a lot more than eight images, and I know there are no old versions, because I didn't start coding until all the sprites were done. |
GimmeCat
|
10/5/2017 | |
And the button is using its own sprite, or the base sprite? If it's using the base sprite, does that mean it looks identical in pose 0 as the base agent? |
the1whoscreams
|
10/5/2017 | |
All the sprites for the machine are in the same file. |
Fuzzy Dragonhat
Pilla
|
10/6/2017 | |
Are the sizes pf image 0 and 7 identical? If not it can throw an error
Visit my Creatures blog/website - Pilla's DS Agents
Join us on Discord - Caos Coding Cave
Visit/contribute to the Creatures Wiki |
the1whoscreams
|
10/6/2017 | |
No, and those numbers are assuming that the base image is actually image 10. Before you ask, making the script reference the actual positions of the frames in the sprite makes no difference. |
GimmeCat
|
10/6/2017 | |
Can I see what you have for the button when it's created? The "PAT: BUTT" line (which incidentally is my favourite script command ever) |
the1whoscreams
|
10/6/2017 | |
pat: butt 2 "nichelingmother" 10 1 204 327 1 [10] 301 1 |
Here you go. |
GimmeCat
|
10/6/2017 | |
The image count needs to equal the number of frames used in the animation. You've specified 1 here, but the button animation is requesting two seperate frames.
I can't test this myself so I'm not entirely sure which solution is correct, but you either need to change that first '1' to a '2' or possibly to '8' if that doesn't work.
(The reason for 8 is that maybe it needs to see the whole range, since the two frames being used for the anim aren't contiguous. So like, since you're using frames 10 and 17, maybe it needs to be told all 8 frames between exist even though you're only using two of them.) |
the1whoscreams
|
10/6/2017 | |
I changed that 1 to an 8 and it's throwing the exact same error. |
GimmeCat
|
10/6/2017 | |
And I assume changing it to 2 didn't help either? Just being thorough.
Sorry to say, but I'm out of ideas on this one. You'll need to wait for someone with more experience in this area. |
Malkin
Manager
|
10/6/2017 | |
Maybe it'd help if you could post the whole cos file up? That way we can see how it works as a whole.
My TCR Norns |
the1whoscreams
|
10/6/2017 | |
Here's the whole mess at once.
*This is the install script. The seed will not inject if there is already a mother in the
*world.
inst
enum 3 3 14893
addv va99 1
next
doif va99 eq 0
new: comp 3 3 14893 "nichelingmother" 24 0 500
attr 198
elas 10
accg 2
perm 100
pose 9
mvto 6090 9210
endi
*When activated by the Hand in seed form, check to transform with a dummy agent. If you can
*transform, do it.
scrp 3 3 14893 1
doif pose eq 9
inst
setv va00 -237
setv va01 -332
addv va00 posl
addv va01 post
new: simp 5 1 14893 "nichelingmother" 1 0 0
rtar 5 1 14893
mvto 1 1
doif tmvt va00 va01 eq 1
enum 5 1 14893
kill targ
next
targ ownr
mvby -237 -332
pose 0
attr 192
*These are the buttons. Message IDs are as follows:
*300: Revert to seed form.
*301: Vend red pheromone.
*302: Vend green pheromone.
*303: Vend white pheromone.
*304: Vend gray pheromone.
*305: Vend black pheromone.
*306: Vend yellow pheromone.
*307: Vend pink pheromone.
*Seed button.
pat: butt 1 "nichelingmother" 9 1 230 273 1 [9] 300 1
*Red button.
pat: butt 2 "nichelingmother" 10 1 204 327 8 [10] 301 1
*Green button.
pat: butt 3 "nichelingmother" 11 1 204 314 8 [11] 302 1
*White button.
pat: butt 4 "nichelingmother" 12 1 218 304 8 [12] 303 1
*Gray button.
pat: butt 5 "nichelingmother" 13 1 232 304 8 [13] 304 1
*Black button.
pat: butt 6 "nichelingmother" 14 1 246 304 8 [14] 305 1
*Yellow button.
pat: butt 7 "nichelingmother" 15 1 260 314 8 [15] 306 1
*Pink button.
pat: butt 8 "nichelingmother" 16 1 260 327 8 [16] 307 1
*Pheromone hatch.
pat: dull 9 "nichelingmother" 3 217 315 1
else
kill targ
targ ownr
rtar 1 2 10
doif targ ne null
mesg wrt+ targ 126 "This is not a safe location!" ownr 0
endi
endi
endi
endm
*Revert to seed form.
scrp 3 3 14893 300
inst
pat: kill 1
pat: kill 2
pat: kill 3
pat: kill 4
pat: kill 5
pat: kill 6
pat: kill 7
pat: kill 8
pat: kill 9
pose 9
mvby 237 200
attr 198
endm
*Vend red pheromone. This is the one that's completely freaking borked. I realize that the
*mvto doesn't move it to the right place, but I'll handle that later.
scrp 3 3 14893 301
part 2
anim [7 0]
over
part 9
anim [0 1 2 3 4 5]
setv va00 posx
setv va01 posy
over
inst
new: simp 2 25 14895 "nichelingmother" 8 24 510
attr 194
elas 10
accg 2
perm 100
mvto va00 va01
targ ownr
part 9
anim [5 4 3 2 1 0]
endm
*Remover script.
rscr
enum 3 3 14893
kill targ
next
enum 2 25 14895
kill targ
next
scrx 3 3 14893 1
scrx 3 3 14893 300
scrx 3 3 14893 301 |
And here's the error...
Runtime error in agent 3 3 14893 script 3 3 14893 301 unique id 242487
Anim change failed - on part 2 which has base 0
[part 2 {@}anim [7 0] over part 9 anim [0 1 2 3 4 5] s ...
Windows NT/2000 6.2 build 9200 ()
OriginalDisplay DirectX (netbabel 148 )
Fri Oct 06 18:38:28 2017 - Savannah - 2.296 b195 |
|
Malkin
Manager
|
10/6/2017 | |
Thanks for that!
I did a search on "anim change failed" - there was a thread from last year in which you had a similar problem. Could the solution offered there be adapted to your present situation?
My TCR Norns |
the1whoscreams
|
10/6/2017 | |
I still can't figure anything out. All I've managed to do is cringe, because that's the default response when I see literally anything I've posted more than six months ago. |
GimmeCat
|
10/6/2017 | |
pat: butt 2 "nichelingmother" 10 1 204 327 8 [10] 301 1
*Green button. |
This still says 1. |
the1whoscreams
|
10/6/2017 | |
I changed the wrong 1.
Whoops.
The script now works perfectly and I am officially stupid. |
GimmeCat
|
10/6/2017 | |
lol
No worries. We all have brain farts. Glad it's working! |
the1whoscreams
|
10/6/2017 | |
Now that I know what's going on, how can I slow an animation down? Putting the same frame in the ANIM ten times in a row feels a little cheaty. |
Sanely Insane
RisenAngel
Manager
|
10/6/2017 | |
FRAT -insert number here-. Put it before the animation.
Note that it'll stay this way for all animations afterward once set, so if you want a future animation to play faster/slower than that you'll need to use FRAT again.
~ The Realm ~
Risen Angel's Creatures Blog
|