Learning how to use lists

NerdinaNutshell

  • *
  • Posts: 141
Recently I’ve been trying to learn how to use lists and was told that I random story generator was the best way to learn how to use them. I had a few questions: How many lists am I going to need? Why are lists required for this? Lastly, if there are more than one lists are most of the lists used to store things such as verbs, adverbs, etc and one of the lists is used “write” the story? Thanks
Plot Twist... I'm a ghost

JeffreyDriver

  • Posts: 1911
I first started using lists to store killed actors so that they wouldn't respawn. I.e. coins that stay collected and don't reappear when the scene loads. This was done by writing a unique ID for each coin to a list when they were collected by the player. Then when the scene reloaded, if the coin's ID existed in the list. Kill the coin immediately.

For another project I have in mind but haven't started yet I was going to do something like a random story generator but it was just going to produce random titles and it would have used lists and random number pickers to pick a random entry.

For example:
Text 1: The
List 1: Amazing, Astounding, Creepy, Hilarious
List 2: Stories, Escapades, Tales, Adventures
Text 2: Of The
List 3: Insidious, Misunderstood, Dapper, Dastardly
List 4: Lord Toff, Red Baron, Keith, Mouse

Then using random number generators to pick random items from each list and write them to a text attribute (ensuring to leave a space between each entry), I would end up with a random title.

E.g. The Hilarious Escapades Of The Dapper Lord Toff

Things get more complex if you want to prevent duplicates, but referring back to my coin example, when a new title is produced, write it to another list and then everytime a new title is produced, check if it exists on that list. If not, write it out, otherwise generate another random title.

(Hopefully I'm still making sense!)

In my current game I'm making extensive use of lists. I'm happy to try and explain more and post some code if you'd like to see.
Current Projects:
Horror Point & Click Episode 1.
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

NerdinaNutshell

  • *
  • Posts: 141
Yeah I think I get lists for the most part but I do have one question. How would I make a list that stores x y coordinates? Thanks
Plot Twist... I'm a ghost

JeffreyDriver

  • Posts: 1911
You can write that to the same entry in a list as just numbers separated by a space E.g '32 32'

If you're consistent in writing the X value first, then the Y value second, you can get that entry and split it into a new temporary list: NUMBERS & TEXT > TEXT > SPLIT > Split TEXT into words.

You then know that item 0 in the temporary list will be the X value, and item 1 will be the Y.

There's also the 'Split TEXT using seperator TEXT' block which is useful if some of your data has spaces in.

In my current project, most of the data is stored in tiles as that's what the player interacts with.

The format is this: "Puzzle Name:Meta Information:Text 1: Text 2"

PUZZLE NAME is for a kill list. Completed puzzles are sent to a list
META INFORMATION does lots of things which I won't go into
TEXT 1 shown before a puzzle is completed
TEXT 2 show after a puzzle is completed

When the player interacts with a tile I get that data and separate it into a list using a colon and send it to another behaviour.
Current Projects:
Horror Point & Click Episode 1.
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

NerdinaNutshell

  • *
  • Posts: 141
You can write that to the same entry in a list as just numbers separated by a space E.g '32 32'

If you're consistent in writing the X value first, then the Y value second, you can get that entry and split it into a new temporary list: NUMBERS & TEXT > TEXT > SPLIT > Split TEXT into words.

You then know that item 0 in the temporary list will be the X value, and item 1 will be the Y.


Sorry, I'm not sure I understand what you're saying here.
Plot Twist... I'm a ghost

Luyren

  • *
  • Posts: 1538
Check the attached image. The first print block will print 10, the second print block will print 20.
Working.

NerdinaNutshell

  • *
  • Posts: 141
Oh I see, thanks for clearing that up
Plot Twist... I'm a ghost

NerdinaNutshell

  • *
  • Posts: 141
I tried to place an actor using lists but for some reason it places the actor at 0,0. I can’t figure out how to fix it. I can’t use the item block because I’m adding more values to the list. Does anyone know what I’d do? Thanks.
Plot Twist... I'm a ghost

CmdrWhitey13

  • Posts: 498
Hull the item block to the split 0 and replace 0 with item for both parts.

Hope it helps.

Bombini

  • *
  • Posts: 1181
You can also just do it very simple:
listA:
item#0 = x coordinates
item#1 = y coordinates
item#2 = amount health
...
I use one list where i store almost all data of the whole game.