Initialisiere Variablen korrekt - Error

  • GM 8
  • Initialisiere Variablen korrekt - Error

    Hallo alle miteinander!

    [hide='Alter Post']Wiedermal ein Problem mit Variablen, die anscheinend nicht initialisiert werden.
    Folgende Situation: In einem Raum ist das Controller-Objekt. Es initialisiert die wichtigsten Variablen, anschliessend prüft es, ob ein Spiel geladen wird oder ob neu begonnen wird. Je nach dem, welche Situation eintrifft, wird ein Objekt erstellt. Das Objekt sollte dann auf die zuvor initialisierten Variablen zugreifen - SOLLTE. Und hier liegt das Problem.

    obj_controller :event_create:
    Spoiler anzeigen

    GML-Quellcode

    1. var handle;
    2. // SETTINGS
    3. show_message("Initialisiere 'draw_gameover'!");
    4. draw_gameover = false;
    5. show_message("Ende!");
    6. show_message("Initialisiere 'draw_question'!");
    7. draw_question = true;
    8. show_message("Ende!");
    9. time = 10;
    10. live = 3;
    11. already_set = false;
    12. // END SETTINGS
    13. // AUFBAU DER LADEDATEI
    14. /*
    15. Zeile 1: Frage-Nr.
    16. Zeile 2: Objekt-Name der Frage
    17. */
    18. if (global.load[0] == true)
    19. {
    20. if (file_exists(global.load[1]))
    21. {
    22. handle = file_text_open_read(global.load[1]);
    23. if (object_exists(file_text_read_string(handle)))
    24. {
    25. instance_create(x,y,file_text_read_string(handle));
    26. instance_destroy();
    27. exit;
    28. }
    29. else
    30. {
    31. message("Fehler beim Laden; das angeforderte Objekt existiert nicht.","Error");
    32. room_goto(room_menu);
    33. exit;
    34. }
    35. file_text_close(handle);
    36. }
    37. else
    38. {
    39. message("Dieser Spielstand ist leer.","Warning");
    40. room_goto(room_menu);
    41. exit;
    42. }
    43. }
    44. else
    45. {
    46. instance_create(x+25,y+25,obj_frage_1);
    47. instance_destroy();
    48. exit;
    49. }
    Alles anzeigen


    obj_frage_1 :event_draw:
    Spoiler anzeigen

    GML-Quellcode

    1. if (obj_controller.draw_gameover == true)
    2. {
    3. obj_controller.draw_question = false;
    4. if (already_set == false)
    5. {
    6. obj_controller.live-=1;
    7. already_set=true;
    8. }
    9. // ZEICHE GAME-OVER & NOCHMAL VERSUCHEN
    10. draw_set_color(c_black);
    11. draw_set_halign(fa_center);
    12. draw_set_valign(fa_middle);
    13. draw_rectangle(room_width/2-355,room_height/4-100,room_width/2+355,room_height/4+100,false);
    14. // EINE SCHWARZE LINIE DURCH DAS GANZE
    15. draw_line_width(0,room_height/4,room_width/2-355,room_height/4,4);
    16. draw_line_width(room_width/2+356,room_height/4,room_width,room_height/4,4);
    17. // IN WEISSER SCHRIFT "GAME OVER"
    18. draw_set_font(font_title);
    19. draw_set_color(c_white);
    20. draw_text(room_width/2,room_height/4,"GAME OVER");
    21. // IN DER MITTE EIN ROTES RECHTECK
    22. // GELBE LINIE DADURCH
    23. // Button 1
    24. if (mouse_x > room_width/2-137.5 and mouse_x < room_width/2+137.5 and mouse_y > room_height/4+225 and mouse_y < room_height/4+275)
    25. {
    26. draw_set_color(c_yellow);
    27. draw_rectangle(room_width/2-137.5,room_height/4+225,room_width/2+137.5,room_height/4+275,false);
    28. draw_set_color(c_red);
    29. draw_line_width(0,room_height/4+250,room_width/2-138,room_height/4+250,2);
    30. draw_line_width(room_width/2+138,room_height/4+250,room_width,room_height/4+250,2);
    31. }
    32. else
    33. {
    34. draw_set_color(c_red);
    35. draw_rectangle(room_width/2-137.5,room_height/4+225,room_width/2+137.5,room_height/4+275,false);
    36. draw_set_color(c_yellow);
    37. draw_line_width(0,room_height/4+250,room_width/2-138,room_height/4+250,2);
    38. draw_line_width(room_width/2+138,room_height/4+250,room_width,room_height/4+250,2);
    39. }
    40. // Ende
    41. //IN SCHWARZER SCHRIFT "NOCHMALS VERSUCHEN"
    42. draw_set_color(c_black);
    43. draw_set_font(font_menu);
    44. draw_text(room_width/2,room_height/4+250,"NOCHMAL VERSUCHEN");
    45. }
    46. if (obj_controller.draw_question == true)
    47. {
    48. // ZEICHNE FRAGE, ANTWORTEN, ZEIT & LEBEN
    49. draw_set_color(c_red);
    50. draw_set_halign(fa_left);
    51. draw_set_valign(fa_middle);
    52. draw_line_width(0,room_height/4,room_width/4,room_height/4,4);
    53. draw_rectangle(room_width/4-150,room_height/4-85,room_width/4+200,room_height/4+85,false);
    54. draw_line_width(room_width/4+150,room_height/4,room_width,room_height/4,4);
    55. draw_set_color(c_black);
    56. draw_set_font(font_question);
    57. draw_text_ext(room_width/4-125,room_height/4,question,-1,room_width/4+150);
    58. draw_set_halign(fa_center);
    59. draw_set_valign(fa_middle);
    60. // Button 1
    61. if (mouse_x > room_width/2-200 and mouse_x < room_width/2+75 and mouse_y > room_height/4+125 and mouse_y < room_height/4+175)
    62. {
    63. draw_set_color(c_yellow);
    64. draw_rectangle(room_width/2-200,room_height/4+125,room_width/2+75,room_height/4+175,false);
    65. draw_set_color(c_red);
    66. draw_line_width(0,room_height/4+150,room_width/2-200,room_height/4+150,2);
    67. draw_line_width(room_width/2+76,room_height/4+150,room_width,room_height/4+150,2);
    68. }
    69. else
    70. {
    71. draw_set_color(c_red);
    72. draw_rectangle(room_width/2-200,room_height/4+125,room_width/2+75,room_height/4+175,false);
    73. draw_set_color(c_yellow);
    74. draw_line_width(0,room_height/4+150,room_width/2-200,room_height/4+150,2);
    75. draw_line_width(room_width/2+76,room_height/4+150,room_width,room_height/4+150,2);
    76. }
    77. // Ende
    78. // Button 2
    79. if (mouse_x > room_width/2-125 and mouse_x < room_width/2+150 and mouse_y > room_height/4+200 and mouse_y < room_height/4+250)
    80. {
    81. draw_set_color(c_yellow);
    82. draw_rectangle(room_width/2-125,room_height/4+200,room_width/2+150,room_height/4+250,false);
    83. draw_set_color(c_red);
    84. draw_line_width(0,room_height/4+225,room_width/2-125,room_height/4+225,2);
    85. draw_line_width(room_width/2+151,room_height/4+225,room_width,room_height/4+225,2);
    86. }
    87. else
    88. {
    89. draw_set_color(c_red);
    90. draw_rectangle(room_width/2-125,room_height/4+200,room_width/2+150,room_height/4+250,false);
    91. draw_set_color(c_yellow);
    92. draw_line_width(0,room_height/4+225,room_width/2-125,room_height/4+225,2);
    93. draw_line_width(room_width/2+151,room_height/4+225,room_width,room_height/4+225,2);
    94. }
    95. // Ende
    96. // Button 3
    97. if (mouse_x > room_width/2-50 and mouse_x < room_width/2+225 and mouse_y > room_height/4+275 and mouse_y < room_height/4+325)
    98. {
    99. draw_set_color(c_yellow);
    100. draw_rectangle(room_width/2-50,room_height/4+275,room_width/2+225,room_height/4+325,false);
    101. draw_set_color(c_red);
    102. draw_line_width(0,room_height/4+300,room_width/2-50,room_height/4+300,2);
    103. draw_line_width(room_width/2+226,room_height/4+300,room_width,room_height/4+300,2);
    104. }
    105. else
    106. {
    107. draw_set_color(c_red);
    108. draw_rectangle(room_width/2-50,room_height/4+275,room_width/2+225,room_height/4+325,false);
    109. draw_set_color(c_yellow);
    110. draw_line_width(0,room_height/4+300,room_width/2-50,room_height/4+300,2);
    111. draw_line_width(room_width/2+226,room_height/4+300,room_width,room_height/4+300,2);
    112. }
    113. // Ende
    114. // Antworten schreiben
    115. draw_set_font(fnt_bold);
    116. draw_set_color(c_black);
    117. draw_set_halign(fa_left);
    118. draw_set_valign(fa_middle);
    119. draw_text_ext(room_width/2-195,room_height/4+150,videos[0,0],-1,270);
    120. draw_text_ext(room_width/2-120,room_height/4+225,videos[1,0],-1,270);
    121. draw_text_ext(room_width/2-45,room_height/4+300,videos[2,0],-1,270);
    122. // Ende
    123. // Zeit & Leben
    124. draw_set_valign(fa_bottom);
    125. draw_text(5,room_height-5,"NOCH "+string(obj_controller.time)+" SEKUNDEN!");
    126. draw_set_halign(fa_right);
    127. draw_text(room_width-5,room_height-5,"NOCH "+string(obj_controller.live)+" LEBEN!");
    128. // ENDE
    129. }
    Alles anzeigen



    Und dann.... DAS:

    Mein doofes Projekt das Variablen nicht erkennt, und ja, wahrscheinlich liegt der Fehler bei mir schrieb:


    ___________________________________________
    ERROR in
    action number 1
    of Draw Event
    for object obj_frage_1:

    Error in code at line 1:
    if (obj_controller.draw_gameover == true)
    ^
    at position 20: Unknown variable draw_gameover



    [hide='Wichtige Hinweise']
    • Im Raum ist nur das Objekt "obj_controller" platziert, kein anderes.
    • Der Raum hat kein Creation-Code
    • Ich habe das ganze auch bereits mit globalvar bzw. global.VAR probiert - Ergebnis ist das gleiche
    • Wenn ich in den "Global Game Settings" uninitialisierte Variablen als 0 definieren lasse, passiert im Game gar nichts
    • Die "show_message()" Funktionen bei der Variablen-Initialisierung sind zum debuggen. Die Messages werden auch ausgegeben.
    [/hide]

    Ich hoffe das reicht an Informationen, und bin froh um jede noch so hilfreiche Antwort! Danke![/hide]

    Entschuldigung, hat sich erledigt! Logischerweise gibt es die Variable "obj_controller.draw_question" ncihtmehr, weil ich am ende des Create-Events das Controller-Objekt zerstöre! :headtouch:

    Danke trotzdem für's Lesen!
    :thumbsup:

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von jlsnews ()

  • Benutzer online 1

    1 Besucher