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.
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?
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?
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.
Hello, @jasondelaat
I am also trying to do something that involves randomly generated text in my game.
I'm trying to make it so that you get a random message each time you get a game over, so I wrote something like this:
GOMSG={"GAME OVER", "U DED", "OH NOES", "DEADEDED"}
IF (GAME_OVER) THEN
PRINT(RND(GOMSG),44,44,7)
The problem is that the code prints a random message from the array each frame instead of just one. How can I make it so that it prints just one message and stops there?
@W.2026 I've done this before. There are probably lots of ways, but the way I do it is to pick the random message and store it in a variable before I transition to the game over game state. So basically, wherever you're setting GAME_OVER to true, assign RND(GOMSG) to a variable, then use that to print instead of doing the RND every time. Something like:
if hit_points <=0 and not game_over then msg=rnd(gomsg) game_over=true end |
Then in your _draw() function:
print(msg,44,44,7) |
[Please log in to post a comment]