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

KaliYuga

Villager
Member
Joined
Oct 3, 2016
Messages
7
Reaction score
0
First Language
English
Primarily Uses
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
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,528
Reaction score
14,259
First Language
English
Primarily Uses
RMVXA
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.
 

KaliYuga

Villager
Member
Joined
Oct 3, 2016
Messages
7
Reaction score
0
First Language
English
Primarily Uses
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.
 
Last edited by a moderator:

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,528
Reaction score
14,259
First Language
English
Primarily Uses
RMVXA
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.
 

KaliYuga

Villager
Member
Joined
Oct 3, 2016
Messages
7
Reaction score
0
First Language
English
Primarily Uses
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?

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
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Frostorm wrote on Featherbrain's profile.
Hey, so what species are your raptors? Any of these?
... so here's my main characters running around inside "Headspace", a place people use as a safe place away from anxious/panic related thinking.
Stream will be live shortly! I will be doing some music tonight! Feel free to drop by!
Made transition effects for going inside or outside using zoom, pixi filter, and a shutter effect
I have gathered enough feedback from a few selected people. But it is still available if you want to sign up https://forums.rpgmakerweb.com/index.php?threads/looking-for-testers-a-closed-tech-demo.130774/

Forum statistics

Threads
105,992
Messages
1,018,189
Members
137,771
Latest member
evoque
Top