• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How to make a character say different lines for different instances?

  • Thread starter Artintheblankvoid001
  • Start date
A

Artintheblankvoid001

Guest
Basically, I'm trying to get a character, Naomi, to say one thing when the player bumps into her, and if he does it twice more, Naomi chases the player. How would I do that?
 

kburkhart84

Firehammer Games
This question is pretty broad. Usually the best thing to do is to try doing something yourself, and then post actual code with what you have tried, with details of what it does, and what you wanted it to do. Then, we can help you.

I will say however, that what you want could be done with a thing called a State Machine. Look that up, see how it works, and then you will have an idea of something to get you started with.
 

woods

Member
set a variable to keep track of how many times she has been bumped by the player..

i would go something like this..

obj_Naomi create event
Code:
bumped = 0;
obj_Naomi collision with player event

bumped++


obj_Naomi step event
Code:
if place_meeting(x,y,obj_player)
{
bumped++;
if (bumped = 1)
{
// do something
}
if (bumped = 2)
{
// do something else
}
if (bumped = 3)
{
// do something
bumped = 0; // resets the bump count
}
}
 
A

Artintheblankvoid001

Guest
Alright, thanks, I'll give this a shot! And to
kburkhart84, I appreciate what you said as well!
What code should I use to get Naomi to say, "Oh, do be careful!"? The timeframe of the story is the Dark Ages.
 
Last edited by a moderator:
A

Artintheblankvoid001

Guest
Okay, thanks woods! I tried it, but it didn't work.
Here's how I set it up:

Create Event:
///Settings
image_speed = 0;
bumped = 0;

Collision Event:
///Naomi Scolds Player for bumping into her
if place_meeting(x,y,obj_Player)
{
bumped++;
if (bumped = 1)
{
draw_text(obj_Naomi.x, obj_Naomi.y+32,"Oh! Do be careful!");
}
if (bumped = 2)
{
draw_text(obj_Naomi.x, obj_Naomi.y+32,"Samuel... are you doing this deliberately?");
}
if (bumped = 3)
{
draw_text(obj_Naomi.x, obj_Naomi.y+32,"...");
}
if (bumped = 4)
{
draw_text(obj_Naomi.x, obj_Naomi.y+32,"THAT IS ENOUGH!")
move_towards_point(obj_Player.x, obj_Player.y, 4);
}
if (place_meeting(x,y, obj_Player))
{
bumped = 0;
}
}
I tried to go off what you gave, but It doesn't display anything. What should I do?
EDIT: I realized what I screwed up, never mind.
 
Last edited by a moderator:
A

Artintheblankvoid001

Guest
Yeah, I thought so. It still won't show. My coding's there, I moved some of the coding into a draw GUI event and tweaked it a bit, but nada.
 

woods

Member
Code:
.
.
.
if  (place_meeting(x,y, obj_Player))
{
bumped = 0;
}
this is the issue i think..
you are setting the bumped variable back to 0 every time..
at the end...move the "bumped = 0" out of its own if statement and into the "bumped=4" if statement
 

woods

Member
draw_text has to go in the draw event..
so in the step event we could have a variable that holds the string to draw, and in the draw event draw the text...

kinda like this:


obj_Naomi create event

Code:
bumped = 0;
my_text = "";
obj_Naomi step event
Code:
if place_meeting(x,y,obj_Player)
{
bumped++;
 
if (bumped = 1)
{
my_text = "Oh! Do be careful!" ;
} 
if (bumped = 2)
{
my_text = "Samuel... are you doing this deliberately?";
} 
if (bumped = 3)
{
my_text = "...";
}
if (bumped = 4)
{
my_text =  ,"THAT IS ENOUGH!" ;
bumped = 0;
}
}
obj_Naomi draw event
Code:
draw_text(x,32, string(my_text));

notice that bumped = 0 is inside the if statement for the 4th bump... this is to reset the variable to zero and restart her list of chat..
you had it in its own if statement..forcing the bumped to stay at 0 the whole time.


also im not sure that having place_meeting(x,y,obj) in the collision event may have messed things a bit.. but this should work in the step event.
we change the variable my_text in the step event and drat the contents of that variable in the draw event.
 
Top