Random Name Generation

0 favourites
  • 12 posts
From the Asset Store
Template for dungeon/maze generation, using wave function collapse
  • Hello friends,

    I'm making a little game where you fling astronauts around a solar system. Every time you miss the target with the flung astronaut, I want to show a random rank and name at the top of the screen to show that it's another person being flung next. See image

    I have a text file containing all the ranks that I want to choose from, and I have a text file containing all the names that I want to choose from. Each time an astronaut misses I want to choose from those two lists to create another random rank/name combination

    The rank file is manageably long, but the names file contain thousands of names.

    How do I best achieve this? I have tried to do it using Arrays but I'm genuinely stumped after looking at tutorials.

    Any help would be deeply appreciated

    Thanks <3

  • Forgot to include the image! See below (hopefully 😬)

  • How about creating two arrays: one for ranks ("ranksArray", 1000 rows) and second for names ("namesArray", 5000 rows).

    Then imagine text object that holds your generated name.

    So:

    text object - set text to: ranksArray.At(round(random(0, 999)))&" "&namesArray.At(round(random(0,4999)))

  • Hey, thanks so much for replying! Yes this sounds like exactly what I need. So the next question is, how do I turn these lists into usable arrays? I know how to create an array manually, by typing everything into cells in the array editor. But how do I do this with large lists? I don't want to have to enter in 1000 names into an array. How do I turn these lists into usable arrays? Apologies if that is a dumb question.

  • If you have a .txt file, that is comma separated, for example. Bill,Jane,Fred,Mable, you can import this file into Construct.

    Then use the Ajax Plugin to do something like this.

    This will load it into an array.

  • That's fabulous, thanks sizcoz that's really helpful I don't fully understand everything in that code but I understand what it's supposed to do. I'll give that a try if have any problems I'll be back. Thanks again x

  • Success! The array populates with names! I can see from the debug view that on start of layout the array is being populated with the names in the text file. Thanks so much for that.

    I am now having difficulty with the second part. I am trying to use the code suggested above provided by KacperStasieluk (see printed below)

    text object - set text to: ranksArray.At(round(random(0, 999)))

    I have of course changed the array name and array length to match my situation, but when I run the layout the text object simply reads "0". I don't know what I'm missing. I have tried using slightly different code which I've found in other threads, but the text box always reads "0". I don't understand. Any help is greatly appreciated.

    You can find some images here: imgur.com/a/iDAJVdm

  • Firstly try using int(random(0,999)) rather than round. The last image in your gallery "code woes" doesn't display. It is easier to get help if you post a link to your project file so people can open it up and have a look :)

  • Thanks for the advice calminthenight. Sadly RankArray.at(int(random(0,16))) doesn't seem to work either. Whenever the layout loads, the text box still simply reads "0". Perhaps it's something to do with how I made the array?

    You can find a link to my project files below. You can find what I'm talking a bout in the 'Level Events' event sheet, under the 'Populating Arrays' and 'Start of Layout' event groups.

    dropbox.com/s/e7stqb0zd858tfs/Astronaut%20Fling.c3p

  • Ok easy fix. Because you have two 'on start of layout events' with the ajax 'on completed' event in between them it looks like they would trigger in order from top to bottom. However, what actually happens is that both of the on start of layout events trigger first (because it's the start of the layout) and then the ajax on completed event triggers. So the reason your RankTxt displays 0 is because there is no data loaded into the array yet when you are asking the text to be set.

    Move your set text action to event #6 and place it after the 'RankArray' Set value action.

    Also you need to increase the size of your text box, or decrease the font size as some of the larger names won't display.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes, that's the problem as the above user explained. And yes, increase the text box size (or reduce font).

    Alternatively, if you want Ranktxt exactly where it is, then you can just do this:

    This 'Wait 0 seconds' simply skips the following actions and runs them on the 'next tick'. (So by then, it has already completed reading and writing the Array, and comes back to update Ranktxt in nearly 0 seconds)

  • Brilliant! After lots of messing about I have finally gotten it working! I used the second solution in the end for organisations sake, but I understand the first explanation and have learnt valuable things about Construct 3. Thanks so much for taking a look and offering advice, I really appreciate. Hope you're both having a good day xx

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