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
Spoiler anzeigen
Alles anzeigen
obj_frage_1
Spoiler anzeigen
Alles anzeigen
Und dann.... DAS:
[hide='Wichtige Hinweise']
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!
Danke trotzdem für's Lesen!
[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

GML-Quellcode
- var handle;
- // SETTINGS
- show_message("Initialisiere 'draw_gameover'!");
- draw_gameover = false;
- show_message("Ende!");
- show_message("Initialisiere 'draw_question'!");
- draw_question = true;
- show_message("Ende!");
- time = 10;
- live = 3;
- already_set = false;
- // END SETTINGS
- // AUFBAU DER LADEDATEI
- /*
- Zeile 1: Frage-Nr.
- Zeile 2: Objekt-Name der Frage
- */
- if (global.load[0] == true)
- {
- if (file_exists(global.load[1]))
- {
- handle = file_text_open_read(global.load[1]);
- if (object_exists(file_text_read_string(handle)))
- {
- instance_create(x,y,file_text_read_string(handle));
- instance_destroy();
- exit;
- }
- else
- {
- message("Fehler beim Laden; das angeforderte Objekt existiert nicht.","Error");
- room_goto(room_menu);
- exit;
- }
- file_text_close(handle);
- }
- else
- {
- message("Dieser Spielstand ist leer.","Warning");
- room_goto(room_menu);
- exit;
- }
- }
- else
- {
- instance_create(x+25,y+25,obj_frage_1);
- instance_destroy();
- exit;
- }
obj_frage_1

GML-Quellcode
- if (obj_controller.draw_gameover == true)
- {
- obj_controller.draw_question = false;
- if (already_set == false)
- {
- obj_controller.live-=1;
- already_set=true;
- }
- // ZEICHE GAME-OVER & NOCHMAL VERSUCHEN
- draw_set_color(c_black);
- draw_set_halign(fa_center);
- draw_set_valign(fa_middle);
- draw_rectangle(room_width/2-355,room_height/4-100,room_width/2+355,room_height/4+100,false);
- // EINE SCHWARZE LINIE DURCH DAS GANZE
- draw_line_width(0,room_height/4,room_width/2-355,room_height/4,4);
- draw_line_width(room_width/2+356,room_height/4,room_width,room_height/4,4);
- // IN WEISSER SCHRIFT "GAME OVER"
- draw_set_font(font_title);
- draw_set_color(c_white);
- draw_text(room_width/2,room_height/4,"GAME OVER");
- // IN DER MITTE EIN ROTES RECHTECK
- // GELBE LINIE DADURCH
- // Button 1
- 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)
- {
- draw_set_color(c_yellow);
- draw_rectangle(room_width/2-137.5,room_height/4+225,room_width/2+137.5,room_height/4+275,false);
- draw_set_color(c_red);
- draw_line_width(0,room_height/4+250,room_width/2-138,room_height/4+250,2);
- draw_line_width(room_width/2+138,room_height/4+250,room_width,room_height/4+250,2);
- }
- else
- {
- draw_set_color(c_red);
- draw_rectangle(room_width/2-137.5,room_height/4+225,room_width/2+137.5,room_height/4+275,false);
- draw_set_color(c_yellow);
- draw_line_width(0,room_height/4+250,room_width/2-138,room_height/4+250,2);
- draw_line_width(room_width/2+138,room_height/4+250,room_width,room_height/4+250,2);
- }
- // Ende
- //IN SCHWARZER SCHRIFT "NOCHMALS VERSUCHEN"
- draw_set_color(c_black);
- draw_set_font(font_menu);
- draw_text(room_width/2,room_height/4+250,"NOCHMAL VERSUCHEN");
- }
- if (obj_controller.draw_question == true)
- {
- // ZEICHNE FRAGE, ANTWORTEN, ZEIT & LEBEN
- draw_set_color(c_red);
- draw_set_halign(fa_left);
- draw_set_valign(fa_middle);
- draw_line_width(0,room_height/4,room_width/4,room_height/4,4);
- draw_rectangle(room_width/4-150,room_height/4-85,room_width/4+200,room_height/4+85,false);
- draw_line_width(room_width/4+150,room_height/4,room_width,room_height/4,4);
- draw_set_color(c_black);
- draw_set_font(font_question);
- draw_text_ext(room_width/4-125,room_height/4,question,-1,room_width/4+150);
- draw_set_halign(fa_center);
- draw_set_valign(fa_middle);
- // Button 1
- 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)
- {
- draw_set_color(c_yellow);
- draw_rectangle(room_width/2-200,room_height/4+125,room_width/2+75,room_height/4+175,false);
- draw_set_color(c_red);
- draw_line_width(0,room_height/4+150,room_width/2-200,room_height/4+150,2);
- draw_line_width(room_width/2+76,room_height/4+150,room_width,room_height/4+150,2);
- }
- else
- {
- draw_set_color(c_red);
- draw_rectangle(room_width/2-200,room_height/4+125,room_width/2+75,room_height/4+175,false);
- draw_set_color(c_yellow);
- draw_line_width(0,room_height/4+150,room_width/2-200,room_height/4+150,2);
- draw_line_width(room_width/2+76,room_height/4+150,room_width,room_height/4+150,2);
- }
- // Ende
- // Button 2
- 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)
- {
- draw_set_color(c_yellow);
- draw_rectangle(room_width/2-125,room_height/4+200,room_width/2+150,room_height/4+250,false);
- draw_set_color(c_red);
- draw_line_width(0,room_height/4+225,room_width/2-125,room_height/4+225,2);
- draw_line_width(room_width/2+151,room_height/4+225,room_width,room_height/4+225,2);
- }
- else
- {
- draw_set_color(c_red);
- draw_rectangle(room_width/2-125,room_height/4+200,room_width/2+150,room_height/4+250,false);
- draw_set_color(c_yellow);
- draw_line_width(0,room_height/4+225,room_width/2-125,room_height/4+225,2);
- draw_line_width(room_width/2+151,room_height/4+225,room_width,room_height/4+225,2);
- }
- // Ende
- // Button 3
- 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)
- {
- draw_set_color(c_yellow);
- draw_rectangle(room_width/2-50,room_height/4+275,room_width/2+225,room_height/4+325,false);
- draw_set_color(c_red);
- draw_line_width(0,room_height/4+300,room_width/2-50,room_height/4+300,2);
- draw_line_width(room_width/2+226,room_height/4+300,room_width,room_height/4+300,2);
- }
- else
- {
- draw_set_color(c_red);
- draw_rectangle(room_width/2-50,room_height/4+275,room_width/2+225,room_height/4+325,false);
- draw_set_color(c_yellow);
- draw_line_width(0,room_height/4+300,room_width/2-50,room_height/4+300,2);
- draw_line_width(room_width/2+226,room_height/4+300,room_width,room_height/4+300,2);
- }
- // Ende
- // Antworten schreiben
- draw_set_font(fnt_bold);
- draw_set_color(c_black);
- draw_set_halign(fa_left);
- draw_set_valign(fa_middle);
- draw_text_ext(room_width/2-195,room_height/4+150,videos[0,0],-1,270);
- draw_text_ext(room_width/2-120,room_height/4+225,videos[1,0],-1,270);
- draw_text_ext(room_width/2-45,room_height/4+300,videos[2,0],-1,270);
- // Ende
- // Zeit & Leben
- draw_set_valign(fa_bottom);
- draw_text(5,room_height-5,"NOCH "+string(obj_controller.time)+" SEKUNDEN!");
- draw_set_halign(fa_right);
- draw_text(room_width-5,room_height-5,"NOCH "+string(obj_controller.live)+" LEBEN!");
- // ENDE
- }
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.
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!

Danke trotzdem für's Lesen!

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