Stuck trying to create a random sentence generator for my NPC events

I hope this is the right place for this! I'm trying to create a script that pulls from three different random lists of phrases to construct random sentences for my NPCs, and I've run into a bit of a snag because I'm pretty new at Ruby. Here's what I've got so far (the dialogue is ridiculous, I know)


@name = "Marley"


@message_1 = "I just discovered",


"My favorite band is The",


"I really enjoy",


"I had a nightmare about",


"you look like a bunch of",


"Nobody but me has ever seen",


"Mainstream stuff is for",


"I'm not rude, society just consists of"


@random = rand(7)


@message_2 = " large",


" purple",


" orange",


" grotesque",


" scaly",


" smelly",


@random = rand(5)


@message_3 = " pustules",


" dolls.",


" eggplants.",


" buffalo.",


" airplane hangars",


@random = rand(4)


$game_message.add(@name + ": " + @message_1[@random]+ @message_2[@random]+ @message_3[@random])


I'm just getting back the same four sentences, ("I really enjoy orange eggplant," "My favorite band is The purple dolls," "I just discovered large pustules," and "you look like a bunch of scaly airplane hangars." None of these is particularly ideal. Does anyone have any suggestions or pointers? I'm pretty stuck.


Thanks so much!

Screen Shot 2016-10-02 at 3.37.39 AM.png
The problem is you only call the random variable once, before the dialogue is selected, so it is the same random variable it is using for message1, message 2 and message 3. You will need three different random variables for this to work, one for message 1, one for message 2 and one for message 3, OR you have to call the random command inbetween adding in the sentence from message 1 and message 2 (and again from message 2 to message 3).


Personally, I'd go with 3 different random variables. Call them random, random2, and random3. Set each of them to a random number from 1 - 4, then change th last line to:


$game_message.add(@name + ": " + @message_1[@random]+ @message_2[@random2]+ @message_3[@random3])


And actually, this does belong under another forum, I'll move it there for you.


I've moved this thread to Learning Ruby and Rgssx. Please be sure to post your threads in the correct forum next time. Thank you.
Thank you so much! That did it! I do have one more question in a similar vein--is there a way to set up a similar process for my npc's name (random 1st and lat names) that are generated once, and then stays the same throughout the random interactions until the player leaves the map? I'd assume this would be a switch-based thing, but I'm not sure.
Hmmm....maybe set a self switch once the name is generated, then reset it when you leave? Or set a variable that you assign to the event in ruby, then clear the variable when you leave? That's the only way I can think of to begin to make it work, and no idea if that will work even.
I'll check that out in a bit! Right now, I'm trying to code a more complex version of the above, and I keep getting an unexpected_$end error. I've gone through and made sure there aren't extra spaces, that my parentheses are closed, etc. What else can I do to narrow down the problem?

Spoiler
Screenshots of code


Screen Shot 2016-10-02 at 3.44.53 PM.png


Screen Shot 2016-10-02 at 3.45.09 PM.png


Screen Shot 2016-10-02 at 3.45.20 PM.png


Screen Shot 2016-10-02 at 3.45.31 PM.png


Screen Shot 2016-10-02 at 3.45.40 PM.png


Screen Shot 2016-10-02 at 3.45.53 PM.png


Screen Shot 2016-10-02 at 3.46.03 PM.png

Original thread: https://forums.rpgmakerweb.com/threads/stuck-trying-to-create-a-random-sentence-generator-for-my-npc-events.69163/