Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Help with arrays...

    Help
    4
    6
    274
    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.
    • K
      kendog400 F last edited by

      I'm trying to write a program, sadly I'm a little lost...
      I need an arrayof three pictures from the assets,
      and then scrool through them every three sec.,
      something like a slideshow.. Take a Peek :
      ........................................................
      loop
      clear()
      array imgs [3]
      img [0] = "Selavi Games / stairs"
      img [0] = "Selavi Games / busStop"
      img [0] = "Selavi Games / cafe"
      img = x
      loadImage ("x", true)
      wait(#)
      loop
      update(0
      return
      ..............................................
      can anyone see what went wrong ?
      I tried to look through the tutorials,
      but I got lost.

      pianofire R 2 Replies Last reply Reply Quote 0
      • pianofire
        pianofire Fuze Team @kendog400 last edited by

        @kendog400 loadImage("x", true) is loading an image called x you need to loadimage(x, true) to load the image stored in the variable x

        1 Reply Last reply Reply Quote 0
        • pianofire
          pianofire Fuze Team last edited by pianofire

          I think that you want something like this:

          // define array and store values
          array imgs[3]
          imgs[0] = "Selavi Games/stairs"
          imgs[1] = "Selavi Games/busStop"
          imgs[2] = "Selavi Games/cafe"
          // loop over values
          for i = 0 to len(imgs) loop
            clear()
            img = loadimage(imgs[i], true)
            drawimage(img, 0, 0)
            update()
            sleep(3)
          repeat
          
          1 Reply Last reply Reply Quote 2
          • R
            rdurbin F @kendog400 last edited by

            @kendog400 you should define the array before your loop. You also have each picture going into index 0. It should be 0,1,2.

            In your for loop you can display your picture and use sleep command for your 3 sec delay

            1 Reply Last reply Reply Quote 1
            • K
              kendog400 F last edited by

              I tried to put some programs in the project section, I want to share
              some programs, so other experts can nick-nack and peck-&-poke
              to see what I've done wrrong, most of the time its spelling errors.
              I wannt to figure out how this project section works....
              I will only be working with cards & card games.....

              1 Reply Last reply Reply Quote 0
              • Dave
                Dave Fuze Team last edited by

                If I was setting this up I think it would look something like this:

                // if I'm going to end up adding more images to an array, I tend not to define the array as a fixed size, since I will have to write out individual filenames anyway.
                // Personally, I find it better to use an array declaration like this:
                imgs = [
                    loadImage("filename_1"),
                    loadImage("filename_2"),
                    loadImage("filename_3")
                ]
                

                With this setup, we don't need to write imgs[3] = loadImage() every time we want to add something. Just add another element like this:

                imgs = [
                    loadImage("filename_1"),
                    loadImage("filename_2"),
                    loadImage("filename_3"),
                    loadImage("filename_4") // the new element
                ]
                

                That should (pretty much) always take place outside of your main loop. Otherwise, you're declaring an array once per frame.

                Since each element of the array is a handle, there's no need to use a separate handle variable when drawing:

                for i = 0 to len(imgs) loop // this loops over each element in the imgs array
                    drawImage(imgs[i], 300 * i, gheight() / 2) // just using an example for the x and y positions.
                repeat
                
                1 Reply Last reply Reply Quote 3
                • First post
                  Last post