Braus's Recent Forum Activity

  • I thought to use something like this but using a dictionary instead of array but I was trying to find something more practical. Thanks for your help.

  • I suggest SVC - create an Excel spreadsheet with all animations and frames. Save as CSV, import to C2 project, load to array.

    It may look like this:

    Sprite1, Animation1, 1, 5, 7, 11, 32, 56, 18, 2, 42, 61

    Sprite1, Animation2, 7, 4, 0, 11, 32, 90, 20, 3, 61, 11

    ....

    Can I populate the array directly with this information?

    How to compare the frames every time the system picks two random numbers?

  • Ok, if you have different image points on different sprites, then my second advice about loading images from files will not work.

    But you still need some way to store all this data about each sprite, their animations and images in each frame.

    How else would your game know that frame10/sprite1 and frame9/sprite2 is the same image?

    You need to put this information into an array first and then check this array when picking a random frame.

    But how can I use the array to check the frames? How to associate the frames with the array values?

  • You can't compare images data (well, you probably can extract them both to BASE64 string and compare strings, but this will be slow and really a huge overkill). So you need some sort of a database. I have already recommended a few options to you in another post:

    Use CSV for storing these lists of numbers. Load CSV into array and pick random numbers from the array, making sure that 2 numbers are not the same.

    Instead of many animations with many duplicating images, add all images as files to your project, create 2 blank sprites and load imaged into them using "Load Image from URL" action. This will also decrease app/download size and memory usage, especially if your images are big.

    Hi dop2000

    Thanks for answering.

    This issue is related to the project that I started when I created the thread you mentioned. All the structure is working because I followed some of your suggestions. Now I just have to fix this particular issue. The problem is that I cannot change the combination of images, the duplicates images and the order of the respective frames because I am defining specific points for each image according to the frame position, and the same image can have a different value depending on the animation in which it is. As the duplicated images may not be in the same frame number, there's no reason for me to use a verification system to check if the frame numbers are the same.

    Although I am using small images I liked your suggestion about using "Load image" but I think it will not solve the problem.

  • I have two sprites with the same 15 animations and with 10 frames with images each of them. Some images are the same and some are not and the equal images can be in the same frame number or not. The programa will choose an animation and a frame number randomly for each sprite and before the program spawn the sprite1 and the sprite2, it needs to check if they have the same animation and after that, if the frames have the same image. I already created the system that check the animations but I don't know how to check the frames once the possibilities are so huge.

    For example, imagine that each frame store a image with a number and the program choose the animations below:

    Animation1 = 1 | 5 | 7| 11 | 32 | 56 | 18 | 2 | 42 | 61 |

    Animation2 = 7 | 4 | 0| 11 | 32 | 90 | 20 | 3 | 61 | 11 |

    If the system choose the frame 4 (11) for both animations or frame 10 for sprite1 (61) and frame 9 for sprite2 (61), it needs to choose another frame for both animations automatically. The problem is that I have 15 animations with different combinations. Any idea?

  • Just use it instead of the first code. I kind of paraphrased the expressions but it should be useable. At the end of it the highest value will be

    Array.at(index1)

    And the second will be

    Array.at(index2)

    You’ll want to reset both vars to 0 before running that event.

    If there is a tie then then it will still work. Barring any flaw to the idea.

    edit:

    Actually that won't work right for finding the second highest value in some cases. Do this instead: loop over the array twice. Again you'll want to reset the variables to 0 before running the two loops again.

    global number index1=0

    global number index2=0

    array: for each x

    compare: array.curvalue >= array.at(index1)

    --- set index1 to array.curX

    array: for each x

    compare: array.curx != index1

    compare: array.curvalue >= array.at(index2)

    --- set index2 to array.curX

    Thanks. It's a nice solution I tried to do something before using your last code. It worked but I think this solution is much better.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I suppose. I’ll try to give a possible example.

    But it’s probably simpler to sort the array. If you want to remember the original indexes, you can add another column and set the values there to the indexes before sorting. If you want to leave the original array alone, you can copy it to another first with the asjson expression.

    var index1=0

    var index2=0

    Array: For each x

    Current value <= array.at(index1)

    —- set index2 to index1

    —- set index1 to curx

    Thanks R0J0hound

    But unfortunately I did not understand how I use this second code with the first one. Could you tell me how it would be if I have these two codes together? I just asking this because the 1st code worked perfectly with my scrip. Now I just need to also get the second highest value and the respective index.

    Taking the opportunity, I've been thinking about the results and I am wondering what would happen if I have a tie. Just a curiosity.

  • You probably can use a dictionary. It’s just something you’d have to try. You can loop over the values much like the array to find the highest value.

    Instead of that expression with max you could do

    var highest=0

    var index=0

    Array: for each x

    Compare: array.curvalue>highest

    —- set highest to array.curvalue

    —- set index to array.curx

    Thanks. I will give it a try.

    I have a last question: is it possible to get the second highest (2nd place) value and index too? Can I use this same code for this?

  • R0J0hound

    Maybe I will have to use an array instead of a dictionary. I saw your suggestion in this thread:

    I am wondering if is possible to also know the index that stores the highest value, using this same code:

    global number highest=0
    
    +----------------------+
    |                           | set highest to array.at(0)
    +----------------------+
       +-------------------+
       | array: for each x | set highest to max(highest, array.curValue)
       +-------------------+[/code:1sjoo0i4]
  • Actually, I just need to know if I can use a dictionary to store the total points of each animation and how can I check which animation has the highest points when the game finishes.

  • Yes. But depending on which group this image is, it worth more or less value.

  • I forgot to say that I need to calculate the points separately for each animation. I think to use a dictionary to store the total points of each one (anima1/anima2/anima3...). When the game finishes, I will have to check which animation has the highest points and show the image of the winner animation then. I would like to know if I can do it with the dictionary (or if I will need to use an array) and how to compare the values in the dictionary (is it possible?) and get the name of the winner.

Braus's avatar

Braus

Member since 17 Jul, 2015

None one is following Braus yet!

Trophy Case

  • 9-Year Club
  • Email Verified

Progress

10/44
How to earn trophies