Results 1 to 6 of 6

Thread: Incrementing variables

  1. #1
    JiC
    JiC is offline
    Newbie
    Join Date
    Sep 2008
    Posts
    26

    Incrementing variables

    Here is a block of code I'm working with
    Code:
          <if fire_on="logic" minimum_delta_vote_time="150" id="CountUSB">
            <boolean_operation type="and">
              <parameter1>
                <boolean_operation type="greater than">
                  <parameter1>
                    <variable do="get" name="usbstatus"></variable>
                  </parameter1>
                  <parameter2>
                    <number>5</number>
                  </parameter2>
                </boolean_operation>
              </parameter1>
              <parameter2>
                <boolean_operation type="less than or equal to">
                  <parameter1>
                    <variable do="get" name="usbtime"></variable>
                  </parameter1>
                  <parameter2>
                    <number>4</number>
                  </parameter2>
                </boolean_operation>
              </parameter2>
            </boolean_operation>
            <then>
              <do function="Change Variable" functionTargetID="usbtime" vote_opinion="+1" vote_priority="Low"></do>
            </then>
          </if>
    Basically what I'm doing here is trying to buy myself a half second or so before I flip an output back off. However, this code takes 'usbtime' from 0 to 1, then it never goes any higher. I'm not sure if it's only entering the <then> once, or if vote_opinion=+1 is not working properly. I'm not changing 'usbstatus' while I'm testing this block. Any ideas?

  2. #2
    JiC
    JiC is offline
    Newbie
    Join Date
    Sep 2008
    Posts
    26
    OK just did some more testing and found out <do function="Change Variable" functionTargetID="usbtime" vote_opinion="+1" vote_priority="Low"></do> sets the value to 1 regardless of its previous value. Is there any way to add a number to a variable?

  3. #3
    JiC
    JiC is offline
    Newbie
    Join Date
    Sep 2008
    Posts
    26
    Ok so found a way to do it. Hopefully this will help some other people. This same idea can be used with steering wheel controls to create different actions if you hold down the buttons. Also it seems to me like since the COM update the MDX is much more accurate with the timer and delta_vote times. Before they seemed random, now they work as they should.

    Now I have it set up so if you hold 'next track' for longer then one second it starts to send fast forwards every half second after that. If you hold next track for less then a second and let go it advances to the next track.

    This timer in my code below allows me to use the fusion brain to trigger a relay for about a second then turn it back off. RR calls a function that turns on a digital output and sets usbstatus to 10 (high) and usbcount to 0. The relay is used to interrupt the +5V wire on the USB cable leading to my hub up front. This solves all pesky problems with my hub and touchscreen on resuming from hibernate (which the fusion brain always comes out of perfectly )

    Code:
          <if fire_on="logic" minimum_delta_vote_time="150" id="CountUSB">
            <boolean_operation type="and">
              <parameter1>
                <boolean_operation type="greater than">
                  <parameter1>
                    <variable do="get" name="usbstatus"></variable>
                  </parameter1>
                  <parameter2>
                    <number>5</number>
                  </parameter2>
                </boolean_operation>
              </parameter1>
              <parameter2>
                <boolean_operation type="less than or equal to">
                  <parameter1>
                    <variable do="set" name="usbtime">
                        <operation type="add">
                          <parameter1>
                            <variable do="get" name="usbtime"></variable>
                          </parameter1>
                          <parameter2>
                            <number>1</number>
                          </parameter2>
                        </operation>
                    </variable>
                  </parameter1>
                  <parameter2>
                    <number>10</number>
                  </parameter2>
                </boolean_operation>
              </parameter2>
            </boolean_operation>
          </if>
          <if fire_on="logic" minimum_delta_vote_time="100" id="ResetUSB">
            <boolean_operation type="and">
              <parameter1>
                <boolean_operation type="greater than">
                  <parameter1>
                    <variable do="get" name="usbstatus"></variable>
                  </parameter1>
                  <parameter2>
                    <number>5</number>
                  </parameter2>
                </boolean_operation>
              </parameter1>
              <parameter2>
                <boolean_operation type="greater than">
                  <parameter1>
                    <variable do="get" name="usbtime"></variable>
                  </parameter1>
                  <parameter2>
                    <number>10</number>
                  </parameter2>
                </boolean_operation>
              </parameter2>
            </boolean_operation>
            <then>
              <do function="Change Variable" functionTargetID="usbstatus" vote_opinion="0" vote_priority="Low"></do>
              <do function="Change Variable" functionTargetID="usbtime" vote_opinion="0" vote_priority="Low"></do>
              <do function="Trigger Output" functionTargetID="Digital Output 0" vote_opinion="Off" vote_priority="Low"></do>
            </then>
          </if>

  4. #4
    Newbie
    Join Date
    Dec 2008
    Posts
    23
    Quote Originally Posted by JiC View Post
    OK just did some more testing and found out <do function="Change Variable" functionTargetID="usbtime" vote_opinion="+1" vote_priority="Low"></do> sets the value to 1 regardless of its previous value. Is there any way to add a number to a variable?
    Yup, try:

    vote_opinion="d+1"

    (That will add 1 to whatever the value is)

  5. #5
    JiC
    JiC is offline
    Newbie
    Join Date
    Sep 2008
    Posts
    26
    Thanks alejoal. I haven't tried it yet but the way you describe is much cleaner

  6. #6
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    Yes + and - are the signs

    d is add the difference to what it is. Without the d it is make it so.

    So "d1" is add 1, "+1" is make it equal to 1, "d-4" is subtract 4, and so on.
    Fusion Brain Version 6 Released!
    1.9in x 2.9in -- 47mm x 73mm
    30 Digital Outputs -- Directly drive a relay
    15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
    Buy now in the MP3Car.com Store

Similar Threads

  1. Increment numerical valued variables
    By Tensai in forum RR Skins
    Replies: 4
    Last Post: 08-14-2007, 01:54 AM
  2. Dividing variables
    By frangolfgt in forum Road Runner
    Replies: 7
    Last Post: 07-19-2007, 08:30 PM
  3. Replies: 10
    Last Post: 02-06-2007, 05:46 PM
  4. Some clarity on variables being sent to flash objects...
    By Sonicxtacy02 in forum Road Runner
    Replies: 7
    Last Post: 10-17-2006, 01:44 PM
  5. How do I use Variables on my Skin ?
    By guino in forum RR FAQ
    Replies: 0
    Last Post: 06-07-2006, 11:51 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •