mardi 20 septembre 2016

Generate text in order

I'm currently making a game in Java (and i'm just starting to use this language). Everything is going pretty well but i'm stuck in an important part.

I want to create dialog box for my PNJs. I manage to create the box with a text when a key is pressed by following several tutorials. I originally made the 5 different texts generate randomly, but I changed my mind and now want them to appear in order (0 then 1 then 2 etc).

My code is the following :

if (keyboard_check_pressed(vk_space)) and (distance_to_object(obj_player) < 5)
{
var str;
switch (irandom(4))
{
    case 0: str = "Text 1";break;
    case 1: str = "Text 2";break;
    case 2: str = "Text 3";break;
    case 3: str = "Text 4";break;
    case 4: str = "Text 5";break;
    default: str = "...";break;
}
scr_text(str,1,view_xview[0],view_yview[0]+130);}

I tried several things (like removing the "irandom" etc) but nothing seems to work. I can't figure out how the rule Switch works.

Thank you for your help

btw i'm using Game maker (if that's an important info)




Aucun commentaire:

Enregistrer un commentaire