Adding/editing arrays...

Get help using Construct 3!

Post » Thu Oct 26, 2017 10:17 am

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
B
14
S
7
G
10
Posts: 226
Reputation: 6,802

Post » Thu Oct 26, 2017 11:02 am

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.
B
53
S
21
G
95
Posts: 2,455
Reputation: 56,125

Post » Thu Oct 26, 2017 11:05 am

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
Follow my progress on Twitter
or in this thread Archer Devlog
B
50
S
22
G
19
Posts: 1,144
Reputation: 14,855

Post » Thu Oct 26, 2017 11:10 am

You can also use Dictionary object instead of array. If you only use a 1 dimensional array.
Follow my progress on Twitter
or in this thread Archer Devlog
B
50
S
22
G
19
Posts: 1,144
Reputation: 14,855

Post » Sat Oct 28, 2017 11:55 am

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.

tunepunk wrote: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 :)
B
14
S
7
G
10
Posts: 226
Reputation: 6,802

Post » Mon Oct 30, 2017 12:05 pm

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:

Image

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.
B
14
S
7
G
10
Posts: 226
Reputation: 6,802

Post » Fri Nov 03, 2017 12:08 pm

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.
B
14
S
7
G
10
Posts: 226
Reputation: 6,802

Post » Fri Nov 03, 2017 12:15 pm

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"
B
53
S
21
G
95
Posts: 2,455
Reputation: 56,125

Post » Fri Nov 03, 2017 1:47 pm

OK - I've done that:

Image

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?
B
14
S
7
G
10
Posts: 226
Reputation: 6,802

Post » Fri Nov 03, 2017 2:06 pm

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.
Last edited by plinkie on Fri Nov 03, 2017 2:12 pm, edited 2 times in total.
B
53
S
21
G
95
Posts: 2,455
Reputation: 56,125

Next

Return to How do I...?

Who is online

Users browsing this forum: The Maddog and 4 guests