Problem mit globalen Variablen

  • Allgemein

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Problem mit globalen Variablen

    Guten Abend,
    ich hab (glaube ich ^^) ein kleines Problem mit meinen Globalen Variablen.
    Ich hab ein Tutorial für einen AnalogStick gemacht und nun versuche ich damit ein Objekt zu bewegen.

    So sieht der Code aus um direct zu definieren:

    GML-Quellcode

    1. var a,b,c,d;
    2. a = view_xview[0]; //Left side of the screen
    3. b = view_yview[0]; //Top side of the screen
    4. c = view_xview[0] + view_wview[0]; //Right side of the screen
    5. d = view_yview[0] + view_hview[0]; //Bottom side of the screen
    6. var pad_x,pad_y,pad_radius,stick_radius;
    7. pad_x = 100 ; //Modify x and y to where ever on the screen. This is the pad co-ordinates from the center of the circle
    8. pad_y = 500 ;
    9. pad_radius = 40; //Radius of the pad thing
    10. stick_radius = 14; //Radius of the stick
    11. draw_sprite(Circle_Pad_Spr,0,pad_x,pad_y);
    12. var stick_x,stick_y;
    13. stick_x = pad_x; //This is the stick co-ordinates from the center of the dot
    14. stick_y = pad_y;
    15. if (stick_active) //If the stick is active, it allows the blue dot (stick) to move around the red circle (pad)
    16. {
    17. stick_x = Mouse_Input_Script(4,pad_x,pad_y,pad_radius - stick_radius);
    18. stick_y = Mouse_Input_Script(5,pad_x,pad_y,pad_radius - stick_radius);
    19. }
    20. draw_sprite(Circle_Stick_Spr,0,stick_x,stick_y);
    21. if (stick_active)
    22. {
    23. var angle,direct,str;
    24. angle = Angle_Script(1,pad_x,pad_y,mouse_x,mouse_y); //This retrieves the degree angle fro mthe pad to the mouse <-A MUST
    25. direct = 1 + (5 * (n_way == 2)); //Defaulting to DOWN
    26. direct = Angle_Script(5,angle);
    27. }
    28. globalvar direct;
    Alles anzeigen



    und so rufe ich das ganze in meiner Timeline ab:

    GML-Quellcode

    1. if(direct == 2)
    2. {
    3. move_towards_point(x, y+2, 10)
    4. }



    der error ist:

    GML-Quellcode

    1. ___________________________________________
    2. FATAL ERROR in
    3. action number 1
    4. at time step5
    5. of time line timeline0:
    6. ############################################################################################
    7. VMError!! Occurred - Push :: Execution Error - Variable Get -5.direct(100030, 0)
    8. at Timeline_timeline0_0 (line 2) - if(direct == 2)
    9. ############################################################################################


    Habe es leider noch nicht geschafft mein Problem zu lösen, weshalb ich nun euch befrage :)
  • Stimmt denn die Eventreihenfolge?
    Ich meine das erste Skript da oben sieht ja wie ein draw-event aus und wenn du die Timeline schon in einem create event gestartet hast, dann wird dessen event möglicherweise vor dem Zuordnen der Variable ausgeführt.
    Schreib mal

    GML-Quellcode

    1. globalvar direct = 0;
    in ein create-event.

    Willst du auf diese Drachen und -eier klicken?
    Sie werden sich freuen ;)