Testi con array

Hai una curiosità o un problema con Game Maker? Domanda e ti sarà risposto!
Rispondi
ben
Membro
Messaggi: 143
Iscritto il: 05/10/2016, 15:40
Specialità: programmazione
Uso: GM:Studio 1.4 Free
Contatta:

Testi con array

Messaggio da ben »

Negli oggetti che uso per i testi delle cutscenes ho messo più messaggi in create perché con un messaggio alla volta avrei appesantito troppo il gioco quindi ho inserito in create:

Codice: Seleziona tutto

//write your messages in an array, starting at 0, like so
message[0] = "Hey!";
message[1] = "Hi!";
message[2] = "?";
message[3] = ". . .";


message_current = 0; //0 is the first number in our array, and the message we are currently at
message_end = 0; //6 is the last number in our array
message_draw = ""; //this is what we 'write' out. It's blank right now
increase = 0.5; //the speed at which new characters are added
characters = 0; //how many characters have already been drawn
hold = 0; //if we hold 'Z', the text will render faster


message_length = string_length(message[message_current]); //get the number of characters in the first message
in draw:

Codice: Seleziona tutto

//Draw the sentence
//Draw Event

x = view_xview + 15; 
y = view_yview + 145;

draw_text_ext(x, y, message_draw, 30, 350); //draw the text at the coordinates
in step:

Codice: Seleziona tutto

if (characters < message_length) { //if current character count is less than the amount in current message* 
    hold = (mouse_check_button_pressed(mb_left)); 
    characters += increase * (1 + hold);//increase speed based on hold
    message_draw = string_copy(message[message_current], 0, characters); //copy string to current character
} 
else { //if current character is more than the amount in the current message
    if (mouse_check_button_pressed(mb_left)) { 
        if (message_current < message_end) { //if there are more messages left to show (0 -> 6, in our case)
            message_current += 1; //increase the message by 1
            message_length = string_length(message[message_current]);  //get the new character length for message
            characters = 0; //set the characters back to 0
            message_draw = ""; //clear the drawn text
        }
        
        }
e per aggiungere gli altri messaggi:

Codice: Seleziona tutto

if (message_current = 1){
        if (mouse_check_button_pressed(mb_left)){
            message_current = 1;
            with(obj_boat)
                {
                 sprite_index = boat;
                }
                
            with(ausiliar_names)
                 {
                  sprite_index = names;
                  image_index = 0;
                 }
            }
        }

 if (message_current = 1){
        if (mouse_check_button_pressed(mb_left)){
            message_current = 2;
            with(obj_boat)
                {
                 sprite_index = boat;
                }
            }
        }

if (message_current = 2){
        if (mouse_check_button_pressed(mb_left)){
            message_current = 3;
            with(obj_boat)
                {
                 sprite_index = boat;
                }
            }
        }
    
if (characters = message_length){
    with(obj_boat)
        {
         sprite_index =boat;
        }
    if (mouse_check_button_pressed(mb_left)){
        instance_destroy();
        with(obj_textbox)
            {
             instance_destroy();
            }
        with(ausiliar_names)
            {
             sprite_index = spr_transparent;
            }
        instance_create(0,0, object_cut2);
        }
        
    }
per cambiare i nomi in base al dialogo:

Codice: Seleziona tutto

if(message_current = 0){
   with(ausiliar_names)
       {
        sprite_index = names;
        image_index = 1;
       }
   
   with(obj_boat)
       {
        sprite_index = boat_speak_ja;
       }
   }
   
if(message_current = 1){
   with(ausiliar_names)
       {
        image_index = 0;
       }
   
   with(obj_boat)
       {
        sprite_index = boat_speak_fr;
       }
   }
   
if(message_current = 2){
   with(ausiliar_names)
       {
        image_index = 0;
       }
   
   with(obj_boat)
       {
        sprite_index = boat_speak_fr;
       }
   }
   
if(message_current = 3){
   with(ausiliar_names)
       {
        image_index = 1;
       }
   
   with(obj_boat)
       {
        sprite_index =boat_speak_ja;
       }
   }
Il codice non funziona e quando il primo messaggio finisce e clicco con il mouse si crea la prossima istanza, che cosa ho sbagliato, soprattutto in base ai codici in step?

Rispondi

Chi c’è in linea

Visitano il forum: Nessuno e 145 ospiti