Adding/editing arrays...

0 favourites
  • 14 posts
From the Asset Store
Customize the animation of character when item changed
  • I'm looking to have a random quote generator on my game on the pause screen - one that will bring up random game reviews from (at first) friends and family. The quote would consist of their review over a couple of lines, plus their Twitter name on the line below.

    Am I right in thinking I can use an array for this rather than a separate database? I've dropped in the array Object into Object Types but I can find the Array Editor - where is this?

    Also - as I'm guessing I'll be dropping the review in the 0 column and the Twitter name in the 1 column - would I call up the random review using something similar to:

    Array > Set Review to choose(0,1,2,3,4,5)

    Cheers all

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can just do this with normal events that relate to setting variables or text, I don't think you need to use an array. There is no array editor, you push the data you want into the array during runtime. If you want to use an array I imagine you would 'choose' a number for x and y, then assign them to a curx, cury from the array.

  • You can find the array editor on the right side in the Project window. Right click on files and choose new > Array

    You can then load this file on to the array object by using Ajax.

    This action will get the Array content:

    -> AJAX: Request quotes.json (tag "quotes")

    Then load it on to the array like this.

    + AJAX: On "quotes" completed

    -> Array: Load from JSON string AJAX.LastData

  • You can also use Dictionary object instead of array. If you only use a 1 dimensional array.

  • Thanks guys - I've looked into this and I think Arrays are the better route than Dictionaries as arrays can have multiple columns whereas dictionaries only seem to have a key and a value.

    You can find the array editor on the right side in the Project window. Right click on files and choose new > Array

    You can then load this file on to the array object by using Ajax.

    This action will get the Array content:

    -> AJAX: Request quotes.json (tag "quotes")

    Then load it on to the array like this.

    + AJAX: On "quotes" completed

    -> Array: Load from JSON string AJAX.LastData

    In regards to the AJAX actions above, how do I add them to the events sheet? There's no mention of AJAX in the Add Condition pop-up box, or am I looking at this wrong and there's another way to do this? Essentially, where do I add the actions you outlined above?

    Thanks all

  • OK - I found the Array object in the Add Condition pop-up but I'm still in the dark as to what/where I add the events.

    Here's a look at my basic array titled ReviewArray:

    On the Properties in the layout I have two text objects (ReviewQuote and ReviewName) - Column 0 should post to ReviewQuote and column 1 should post to ReviewName.

  • All - is there anyone who can help me on this?

    I've no idea what I'm meant to be putting in the event sheet.

    I'm guessing it starts off with:

    Array > ? > ? > ?

    Can anyone help?

    Thanks.

  • ReviewQuote set text to ""&array.at(0,0) would display "Blah blah blah"

    ReviewName set text to ""&array.at(0,1) would display "Mr Grumpy"

  • OK - I've done that:

    But this just brings up the values of 0 and 0.

    I'm guessing I need to attach or refer to the array first - how do I do that?

    Also, how would I get it to select both values from random rows rather from specific rows?

  • It displays the value at 0 because that's the co-ords I gave in the example, nothing specific was asked for. If you want to display a random quote you would probably create a function, before which you set the review parameter to a random number and pass it through as array.at(param(0), 0). You can pass through another param for the name as array.at(param(1),1). You don't have to use a function, you can just set two variables to a random number and assign the co-ordinates to array.at(var1,0) and array.at(var2,1) but I prefer to use functions for things like this.

  • I think you're not really doing it right.

    I created a simple example for you how to load the json to an array and how to display it as a text.

    Hope this helps.

    https://www.dropbox.com/s/fy75e5vrxst7t ... y.c3p?dl=0

  • I think you're trying to do a quote generator like this.

    So I updated the file a little bit.

    https://www.dropbox.com/s/fy75e5vrxst7t ... y.c3p?dl=1

    Click the button to get a random quote.

  • Tunepunk - thats absolutely brilliant - exactly what I was looking for - I can now amend this to fit how I want it to fit in my game.

    Also you've showed me exactly how to attach and call an array in the event sheet - thanks so much for that!

  • Just a nod to say this helped me enormously with loading the file for the array - the manual entry on Arrays doesn't even hint about needing the Ajax plugin to load the file and my array was always full of zeros.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)