How do I Random Text from Array?

Get help using Construct 2

Post » Tue Dec 06, 2016 7:29 pm

I have searched whole internet but cannot find exact info for this step. How I can just simply Load random question from array and display it on screen?
I have array created already. Anymore I need to get my game pick randomly on start of the layout one text from array.
B
6
S
1
Posts: 19
Reputation: 392

Post » Tue Dec 06, 2016 8:31 pm

One trick is to pick a random index, from the Width of the array, and delete it from the array. Each iteration will only pick from the remaining items.
http://www.blackhornettechnologies.com/Construct2Stuff/RandomStringArray.capx
ImageImageImage
B
71
S
22
G
248
Posts: 3,761
Reputation: 138,073

Post » Wed Dec 07, 2016 5:08 pm

Thx for your quick reply. This was good sample. Still I cannot solve my problem which was near by your solution.

Now I have problem that my Array has values loaded from textfile. But my game is appending text as numbers.
Something is wrong. Someday I will laugh to this but today I don't know how to use arrays smoothly :D

Image

Don't pay too much attention to commentlines as I have moved few actionlines places so it's messy.
B
6
S
1
Posts: 19
Reputation: 392


Post » Wed Dec 07, 2016 6:22 pm

Message: Skebab can only post plain text URLS until they have 500 rep. 2 URLS modified. Why?
Lordshiva1948 wrote:Skebab This tutorial might help you

https://www.scirra.com/tutorials/1418/trivia-game

https://www.scirra.com/tutorials/1417/r ... -as-arrays



Thank you ! I think these helped me to clear my ''code''.

Now I have done I think everything I can as following your Trivia Tutorial. I dont have any answer options on my game so I tryed to find out what I dont need.

Now when I am debugging my game I will find every card on their own Array cells. But I cannot set text to be visible. Maybe you can find out why?

Image
B
6
S
1
Posts: 19
Reputation: 392

Post » Thu Dec 08, 2016 10:46 am

Skebab

1st Have you created any Text on layout? if not how you will see it
2nd If you did create Text on Layout, did you set property of Text to be VISIBLE
3rd If you did not create Text on Layout how can you see the TEXT?
B
256
S
39
G
15
Posts: 1,982
Reputation: 41,032

Post » Thu Dec 08, 2016 4:18 pm

Lordshiva1948 wrote:Skebab

1st Have you created any Text on layout? if not how you will see it
2nd If you did create Text on Layout, did you set property of Text to be VISIBLE
3rd If you did not create Text on Layout how can you see the TEXT?


Thx for your reply Lordshiva.

1) Text is on Layout and set Visible
Image

2) Debug mode shows that there is all values nicely in own cells in arrays
Image

3) I have succeeded to get system randomly pick one of the values from array
Image

PROBLEM) I just cannot get this value showed at TEXT on layout :) ????

Instead what I have got working is that I get only numbers showing in layout where text should be showen by editing code.
Sometimes I have even got first text value showed in layout but if system pick up some other cell than array nmbr. 0 it will show only blank.

Here is my code now:
Image
B
6
S
1
Posts: 19
Reputation: 392

Post » Thu Dec 08, 2016 5:03 pm

Post a CAPX. It's too hard to debug by screenshots.
ImageImageImage
B
71
S
22
G
248
Posts: 3,761
Reputation: 138,073

Post » Thu Dec 08, 2016 6:17 pm

blackhornet is quite right my friend. When I look at your code I thought you have not any text on Layout. I am sorry about that
B
256
S
39
G
15
Posts: 1,982
Reputation: 41,032

Post » Thu Dec 08, 2016 6:37 pm

Message: Skebab can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Okay I dont know other way to share capx, I hope this will work:
https://drive.google.com/drive/folders/ ... sp=sharing

Thank you very much for taking me forward with this! :)
B
6
S
1
Posts: 19
Reputation: 392

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests