Variable einem Punkt zuweisen

  • GM 7
  • GML-Quellcode

    1. point[0] = 100; // x-wert
    2. point[1] = 100; //y-wert

    Muss man dann auch so wieder auslesen:

    GML-Quellcode

    1. x = point[0];
    2. y = point[1]


    Für mehrere Punkte:
    Spoiler anzeigen

    GML-Quellcode

    1. point[0,0] = 100 // punkt1 x
    2. point[0,1] = 100 // punkt1 y
    3. point[1,0] = 200 // punkt2 x
    4. point[1,1] = 200 // punkt2 y
    5. point[2,0] = 300 //...


    MfG Waterman7
  • Du kannst es auch als String speichern, ich kenn mich damit nich so aus, aber da würde zum Speichern z.B. punkt=string(mouse_x)+"|"+string(mouse_y); möglich. Beim Auslesen? Keine Ahnung, ich hab mich damit NIE auseinander gesetzt, aber die Hilfe wird dir weiterhelfen.
    Ansonsten im TutorialArchiv sind viele Scripte die Strings benutzen, da kann man sicherlich abgucken wie es funktioniert.
    So far, Schattenphoenix~
    _____________________________________________________________________________
    "Who needs a stairway to heaven...
    If there is an elevator to hell... ?
    "
    - Vergessen
    "Auch ein perfektes Chaos ist etwas vollkommenes."
    - Jean Genet
  • Ich hab da mal was kleines geschrieben:
    point(x, y):

    GML-Quellcode

    1. return string(argument[0]) + "|" + string(argument[1]);

    point_get_x(point):

    GML-Quellcode

    1. var s, p, i;
    2. p = argument[0];
    3. s = "";
    4. for (i = 1; i < string_length(p); i += 1) {
    5. if (string_char_at(p, i) == "|")
    6. return real(s);
    7. s += string_char_at(p, i);
    8. }
    9. return -1;

    point_get_y(point):

    GML-Quellcode

    1. var a, s, p, i;
    2. p = argument[0];
    3. s = "";
    4. a = false;
    5. for (i = 1; i < string_length(p) + 1; i += 1) {
    6. if (a)
    7. s += string_char_at(p, i);
    8. if (string_char_at(p, i) == "|")
    9. a = true;
    10. }
    11. return real(s);
    Alles anzeigen

    Kann man dann so aufrufen:

    GML-Quellcode

    1. var a;
    2. a = point(640, 480);
    3. show_message(string(point_get_x(a))); // liefert 640
    4. show_message(string(point_get_y(a))); // liefert 480
  • Igitt, eine Schleife :P
    Hab mir erlaubt die Codes zu verbessern:

    point(x,y)

    GML-Quellcode

    1. if (!is_real(argument0)) {return "";}
    2. if (!is_real(argument1)) {return "";}
    3. return string(argument0)+"|"+string(argument1);
    point_x(point)

    GML-Quellcode

    1. var str,pos;
    2. str = argument0;
    3. pos = string_pos("|",str);
    4. if (pos==0) {return -1;}
    5. return real(string_copy(str,1,pos-1));
    point_y(point)

    GML-Quellcode

    1. var str,pos;
    2. str = argument0;
    3. pos = string_pos("|",str);
    4. if (pos==0) {return -1;}
    5. return real(string_copy(str,pos+1,string_length(str)-pos));

    Und das Beispiel:

    GML-Quellcode

    1. a = point(4,2);
    2. b = point(-293,0.227);
    3. show_message(a+": X="+string(point_x(a))+", Y="+string(point_y(a)));
    4. show_message(b+": X="+string(point_x(b))+", Y="+string(point_y(b)));
    5. // Ergebnis:
    6. // 4|2: X=4, Y=2
    7. // -293|0.23: X=-293, Y=0.23