🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    UIFLOW variable declaration issues - need help

    FAQS
    2
    7
    12.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jpilarski
      last edited by jpilarski

      I am having issues using a variable in a for loop when I am using UIFLOW. Here are two separate issues. In the first example you can see the start and stop value are not being properly populated with the value from the block. This happens as soon as a variable is used in the for loop.
      TypeError("generator' object is not iterable",)
      alt text

      from m5stack import *
      from m5ui import *
      clear_bg(0x111111)
      
      
      btnA = M5Button(name='ButtonA', text='ButtonA', visibility=False)
      btnB = M5Button(name='ButtonB', text='ButtonB', visibility=False)
      btnC = M5Button(name='ButtonC', text='ButtonC', visibility=False)
      rect0 = M5Rect(0, 0, 30, 30, 0x000000, 0xFFFFFF)
      
      step = None
      X = None
      Y = None
      
      def upRange(start, stop, step):
        while start <= stop:
          yield start
          start += abs(step)
      
      
      
      while True:
        step = 40
        for X in upRange:
          for Y in upRange:
            rect0.setBgColor(0x999999)
            rect0.setPosition(X, Y)
        wait(0.001)
      

      This is the code for the second attempt. I'm not sure why it's defining the type as float. The error I get is TypeError('can't convert float to int')
      alt text

      from m5stack import *
      from m5ui import *
      clear_bg(0x111111)
      
      
      btnA = M5Button(name='ButtonA', text='ButtonA', visibility=False)
      btnB = M5Button(name='ButtonB', text='ButtonB', visibility=False)
      btnC = M5Button(name='ButtonC', text='ButtonC', visibility=False)
      rect0 = M5Rect(0, 0, 30, 30, 0x000000, 0xFFFFFF)
      
      start = None
      stop = None
      step = None
      X = None
      Y = None
      
      def upRange(start, stop, step):
        while start <= stop:
          yield start
          start += abs(step)
      
      def downRange(start, stop, step):
        while start >= stop:
          yield start
          start -= abs(step)
      
      
      
      start = 0
      stop = 200
      step = 40
      while True:
        for X in (float(start) <= float(stop)) and upRange(float(start), float(stop), step) or downRange(float(start), float(stop), step):
          for Y in (float(start) <= float(stop)) and upRange(float(start), float(stop), step) or downRange(float(start), float(stop), step):
            rect0.setBgColor(0x999999)
            rect0.setPosition(X, Y)
        wait(0.001)
      
      1 Reply Last reply Reply Quote 0
      • J
        jpilarski
        last edited by

        Am I correct in thinking that if I want to use the blocks and I want to use variables I have to use while() and not range(). This approach does work but it feels so inefficient.
        alt text

        1 Reply Last reply Reply Quote 0
        • J
          jpilarski
          last edited by

          UIFLOW is doing this which is giving TypeError(can't convert float to int)

          start = 0
          stop = 200
          step = 40
          while True:
          for X in (float(start) <= float(stop)) and upRange(float(start), float(stop), step) or downRange(float(start), float(stop), step):

          It looks like UIFLOW should be doing the following and be casting the variable to an int instead of a float. Can you please update UIFLOW or let me know what I need to do to correct this issue

          start = 0
          stop = 200
          step = 40
          while True:
          for X in (int(start) <= int(stop)) and upRange(int(start), int(stop), step) or downRange(int(start), float(stop), step):

          1 Reply Last reply Reply Quote 0
          • H
            heybin
            last edited by

            hello, in v0.1.0, we will add a block to make float to int

            J 1 Reply Last reply Reply Quote 0
            • J
              jpilarski
              last edited by

              That's great news. Please keep up the good work and I look forward to the update. Please see what you can do to add some basic UART bluetooth blocks. I would really like to use the M5stack bluetooth capabilities similarly to the microbit. The microbit adds an easy way to pair to a tablet and send and receive serial messages over bluetooth. This provides an easy path for app development using the board along with a tool like mit app inventor or evothings or some such app maker.

              1 Reply Last reply Reply Quote 0
              • J
                jpilarski @heybin
                last edited by

                @heybin I looked for the float and int block in the v1.0 release but I didn't see them. Can you tell me the status on this issue. By the way it looks like as of 0.91 the python code being generated is now casting all variables used in a for loop to float type and their is no longer an error caused by mixed types. I'm not sure if you are still planning to have blocks to specify types but I think it could be a good feature to have.

                1 Reply Last reply Reply Quote 0
                • J
                  jpilarski
                  last edited by

                  I am still getting a "can't convert float to int" error whenever I use a variable in the by argument in the count with i from to block. If I use an integer block in by it works fine. If I set a variable to the same integer it gives me an error and if I convert to int or convert to float I get the same error. If I click on details it reads: File<'string'> line57 in <module> TypeError: can't convert float to int. This is a bummer since I need to use a variable in the by argument of the block. Any help would be appreciated

                  0_1677231094954_Screenshot 2023-02-24 012950.png

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post