Author Topic: TalkIcon and how to play through the loop x many times  (Read 9795 times)

0 Members and 1 Guest are viewing this topic.

Offline Cloudee1

TalkIcon and how to play through the loop x many times
« on: May 06, 2015, 12:02:34 PM »
Here's another bit of code which has come about as a result of Troflip's decompilation efforts. This bit will create a "talking icon" which will play through a print icons animations however many times you may like for it to.

First in the DCIcon script, add this class to the bottom of the script. You could make it it's own script and then use it to pull in it's functionality, but I really didn't see any reason to in this case.
Code: [Select]
(class TalkIcon of DCIcon
    (properties
        type 4
        state 0
        nsTop 0
        nsLeft 0
        nsBottom 0
        nsRight 0
        key 0
        said 0
        value 0
        view 0
        loop 0
        cel 0
        cycler 0
        cycleSpeed 6
        signal 0
        iterate -1
        iterCnt 0
        saveBits 0
    )

    (method (init)
    (var offsetIterate)
        (if (== cycler -1)
            = cycler 0
        )(else
            (if (cycler)
                (send (= cycler (send cycler:new())):init(self))
            )(else
                (send (= cycler (Fwd:new())):init(self))
            )
        )
        = iterCnt 0
        // Corrects for number of cels in loop
        (if(> iterate -1)
           = offsetIterate (* iterate NumCels(self))
           = iterate offsetIterate
)
        // Corrects for cycleSpeed
        (if(> cycleSpeed 0)
           = offsetIterate (+ (* iterate cycleSpeed) iterate)
           = iterate offsetIterate
)
    )


    (method (draw)
        (var temp0)
        (if (saveBits)
            Graph(8 saveBits)
            Graph(13 nsTop nsLeft nsBottom nsRight)
        )
        = saveBits Graph(7 nsTop nsLeft nsBottom nsRight 3)
        DrawCel(view loop cel nsLeft nsTop 15)
    )


    (method (cycle)
        (var theCel)
        = theCel cel
        (super:cycle())
       
       
      //  (if (not IsObject(cycler) or (== cel theCel))
      //      0
      //  )(else
            (if ((== iterate -1) or (<= iterCnt iterate))
                ++iterCnt
                //(if ((> NumLoops(self) 1) and (loop or (< Random(1 100) 51)))
                //    = loop (^ loop $0001)
                //)
            )(else
                (if (> iterCnt iterate)
                    (if (IsObject(cycler))
                        (send cycler:dispose())
                    )
                    = loop (= cycler (= cel 0))
                )
            )
        )
  //  )
)

Now in the Roomscript that you would like to use a talking icon. You will need to add an instance, just like you would for an actor or other view. In my case, I used view 950, but you will need to set the view, loop, and cel accordingly.
Code: [Select]
(instance testTalkIcon of TalkIcon(properties view 950 loop 0 cel 0))

While you could probably add an init method to that instance, I have always inited my dcIcons in the roomscript. So in the public instance  of your room (the same place as all of your other init's), add in the code
Code: [Select]
  (testTalkIcon:init())

and finally, all that is left to do is trigger it somehow.
Code: [Select]
(if(Said('hi'))
    (testTalkIcon:iterate(1)cel(4))
    Print("Talk Icon 1" #icon testTalkIcon)
   
    (testTalkIcon:iterate(2)cel(0))
    Print("Talk Icon 2" #icon testTalkIcon)
   
    (testTalkIcon:iterate(4)cycleSpeed(10)loop(1))
    Print("Talk Icon 3" #icon testTalkIcon)
)

This code more or less came out of sq4 decompiled code. I made a few adjustments to it because out of the box the iterate property acted like it represented the number of cycles that the icon would animate for. So if you said iterate(6) and the cycleSpeed was set to 6 then you would only see the view change 1 cel. I added a bit of math to take into account the cyclespeed as well as the number of cels in the loop so that 1 iteration equals 1 time through the loop. One thing to note, this will end on the same cel that it began on.
« Last Edit: May 06, 2015, 12:33:29 PM by Cloudee1 »


Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.052 seconds with 21 queries.