Log In  

Hello, all! I have a question about a project I am working on in pico 8 (Random name generator).

I tried rnd (command) at first and that failed for obvious reasons. And now I am in a pickle I can use print and say a = "tammy" and it work's.

But!

When I add more it only works on the first entry? In reading the manual it doesn't say anything that I can see that could help me. Online has been a bust though still interesting.

I also checked out the cart pico map generator (the world name generator part) which help's in that I need to write a function...? It is rather long (and beyond my understanding unless I squint really hard).

Anyone have any way to combine two (or more) names using the print command? Or something else?

Thank you, for your time!

Ps. I am still learning pico 8. I can make (very) simple games and I not versed in each command nor the terms.

P#131209 2023-06-21 23:51 ( Edited 2023-06-21 23:55)

Hi @BlueBirdSings, welcome!

It sounds like you're looking for the concatenation operator - which is two dots like this .. - which takes two strings and combines them into a single string like this:

first = "john "
last = "smith"
full = first..last
print(full) -- will print: john smith

-- you can also do it directly inside the print itself.
print(first..last)

-- and you can join more than two just chaining them together.
-- so instead of having to add a space at the end of 'john' you can do this.
full = "john".." ".."smith"
print(full) -- also prints: john smith

Hope that helps. If that's not exactly what you were asking for could you provide a bit more detail about what it is that you need?

P#131213 2023-06-22 00:33

Thank you, @jasondelaat !

In addition to combining names what has alluded me is the random part...it seem's that rnd only work's for numbers ,so, is there anyway I can randomize a string? Is it a series of string?

Such as...

A = "bob", "tim", "jim"

Is that single string? Or multiple string's?

Further...

Print= A -- somehow randomize the result?

P#131214 2023-06-22 01:00

Ah, I see!

Yes there is. You need to store the names in an array and then you can pass the array to rnd and it will give you back one of the entries.

names = {'tim', 'bob', 'fred'}
print(rnd(names)) -- will print one of those three names at random

You can add as many names as you want to the array.

P#131217 2023-06-22 01:19

[Please log in to post a comment]