• 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!

Legacy GM [SOLVED] Help: Multi-line string output.

A

Alan Régis

Guest
I have a little trouble finding the right words to describe my problem so i'll try be as objective as possible:

What i want:
- Left Click the dice > roll dice > Message on the chatbox: ("You rolled a d6 and got a 5").
- Left click the dice again > same thing, but with the new dice result showing on a new line in the chat box.

What i have:
- Left Click the dice > roll dice > Message on the chatbox: ("You rolled a d6 and got a 5").
- Left click the dice again > New dice result is ok, new line too, but the older lines are updated with the last dice result.

Here's the code (i know its wrong, but anyway, maybe it could be helpful to put me in the right direction...)

Create Event
Code:
show_roll = false ;
dice_type = 6 ;
click_count = 0 ;
Left Click Event:
Code:
randomize() ;
show_roll = true;
dice_roll = irandom_range(1,dice_type) ;
click_count += 1 ;
Draw Event:
Code:
draw_self() ;

pos_vert = obj_chatbox.y + 0;
pos_horiz = obj_chatbox.x + 25 ;

if show_roll
{
    var i;
    for (i = 0; i < click_count ; i += 1)
        {
        draw_set_font(fnt_dice) ;
        dice_result = "Rolled a d" + string(dice_type) + " and got a " + string(dice_roll) ;
        draw_text(pos_horiz, pos_vert + i*16, dice_result);
        }
}
 
S

Street Gaming

Guest
I would create a ds list to which you add string values. Have the list display however many lines of text you want, for examppe four. Then when you want to add a string to the text box execute a script that adds the string and checks if there are too many lines and deletes the older lines until you have only the right ammount of lines. Let me know if that sounds close to what you're shooting for or if you need some help in the implementation.
 
A

Alan Régis

Guest
I would create a ds list to which you add string values. Have the list display however many lines of text you want, for examppe four. Then when you want to add a string to the text box execute a script that adds the string and checks if there are too many lines and deletes the older lines until you have only the right ammount of lines. Let me know if that sounds close to what you're shooting for or if you need some help in the implementation.
Sounds pretty close. I have read the manuals and tried to use ds lists and even arrays, but i lack the knowledge to make a functional expression. Can you give me some explanation about it, if its not asking too much?
 
S

Street Gaming

Guest
No problem. I only have my phone atm, so Ill see what I can do. I personally would create a new object and then call it objMessage or something. I. The create event:

dsText = ds_list_create();

Then in the draw event:

for (i=0;i<4;i+=1) // change 4 to however many lines of text you want
{
draw_text(ds_list_find_value(dsMessage,i),x,y) // replace x and y with wherever you want to draw it


Then, for your text adding script. Call it scrMessage

var message;
message=argument0;
ds_list_add(objMessage.dsMessage,message);

if (ds_list_size(objMessage.dsMessage)>4)
{
ds_list_delete(dsMessage,0);
}



Finally, in your dice, call the script.

scrMessage("text here");
 
A

Alan Régis

Guest
No problem. I only have my phone atm, so Ill see what I can do. I personally would create a new object and then call it objMessage or something. I. The create event:

dsText = ds_list_create();

Then in the draw event:

for (i=0;i<4;i+=1) // change 4 to however many lines of text you want
{
draw_text(ds_list_find_value(dsMessage,i),x,y) // replace x and y with wherever you want to draw it


Then, for your text adding script. Call it scrMessage

var message;
message=argument0;
ds_list_add(objMessage.dsMessage,message);

if (ds_list_size(objMessage.dsMessage)>4)
{
ds_list_delete(dsMessage,0);
}



Finally, in your dice, call the script.

scrMessage("text here");
It took me a while and a lot of trial and error, but i've finally managed to understand the logic behind ds_list thanks to your example. It's all working as intended now. Thank you very much!
 
Top