Pulling random text values out of a bank (But not Array?)

Just started using Construct 2? Post your questions here

Post » Fri Apr 10, 2015 4:52 pm

I'm making a random phrase generation system. It's going to be something like "Thing + ADJ_VAR + NOUN+VAR."

The Noun variable is going to have a ton of nouns in it. Arm, leg, butt, etc. Would the easiest thing to do is make a on Start Layout > Add all the nouns into a 1 dimensional Array and then pull out a random one when asked for it? I just feel like there's an easier way to accomplish this.
B
20
S
5
Posts: 108
Reputation: 1,473

Post » Fri Apr 10, 2015 5:24 pm

What's complicated about that solution with the array? It's just a simple one line expression to fetch a value like that.

Personally I would just add a text file to the project, that contains all the nouns and then, after I've successfully requested the file with ajax, add them to the array with a for loop.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Fri Apr 10, 2015 5:29 pm

Yeah see doing that with a text file would make this so much simpler but I don't know how to do that. What is ajax?

Right now I'm doing it as

On Start of Layout>

Adj_var>Set Value at 0 to "red"
Adj_var>Set Value at 1 to "big"
Adj_var>Set Value at 2 to "arm"

and so on.
B
20
S
5
Posts: 108
Reputation: 1,473

Post » Fri Apr 10, 2015 5:36 pm

https://copy.com/G1eGXoqiTaSVu0jh
Image

Ajax in this case is the ajax object in Construct. Read the Construct 2 manual for more information on it, if you want to know more.


SIDENOTE: If you are working with large arrays/lists, it is probably faster (performance/memory-wise) to set the array's final size right in front of the loop and then just fill it step by step, instead of repeatedly resizing it. So instead of push you set the array width to the tokencount that was used in the for expression. And in the for loop instead of pushing, you use set array at (loopindex-1) to tokenat(...)
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest