Quantcast
Channel: Active questions tagged game-maker - Stack Overflow
Viewing all articles
Browse latest Browse all 189

Dot Notation in GML and how do I use this.function()

$
0
0

I'm making a script using GML. I'm quite new to GML but already have some experience in Python and a little bit in C languages.

Is this even correct?

function tooltip() {    var this = {};    this.__init__ = function() {        this.box = [];        this.cx = obj_cursor.x;        this.cy = obj_cursor.y;    }    this.update = function() {        this.cx = obj_cursor.x;        this.cy = obj_cursor.y;    }    this.create_id = function() {        used_ids = []        for (var i = 0; i < array_length(this.box); i++) {            array_push(used_ids, (this.box[i])._id);        }        if (array_length(used_ids) == 0) return 0;        array_sort(used_ids, true);        for (var i = 0; i < array_last(used_ids); i++) {            if (!array_contains(used_ids, i)) return i;        }        return array_length(this.box);    }    this.create_box = function(_x, _y, _w, _h, _title, _desc, _state = false, _pict = spr_office) {        var _box = {        pos_x : _x,        pos_y : _y,        width : _w,        height : _h,        title : _title,        desc : _desc,        state : _state,        pict : _pict,        _id : this.create_id()        }        array_insert(this.box, _box._id, _box);    }    this.delete_box = function(box_id) {        for (var i = 0; i < array_length(this.box); i++) {            if ((this.box[i])._id == box_id) {                array_delete(this.box, i, 1)                break;             }        }    }    this.print = function(box_id) {        var _data = {};        for (var i = 0; i < array_length(this.box); i++) {            if ((this.box[i])._id == box_id) {                _data = this.box[i];                break;            }        }        var _x = _data.pos_x;        var _y = _data.pos_y;        var _w = _data.width;        var _h = _data.height;        var _t = _data.title;        var _d = _data.desc;        var _p = _data.pict;        var _col = _data.state ? c_white : c_gray;        draw_rectangle_colour(_x - 2, _y - 2, _x + _w+ 2, _y + _h + 2, c_white, c_white, c_white, c_white, false);        draw_sprite_stretched_ext(_p, -1, _x, _y, _w, _h, _col, 1);        if ((_x <= this.cx && this.cx <= _x + _w) && (_y <= this.cy && this.cy <= _y + _h)) {            draw_set_colour(c_black);            draw_rectangle(this.cx, this.cy, this.cx + _w + 6, this.cy + _h + 6, false);            draw_set_colour(c_white);            draw_text_ext(this.cx + 3, this.cy + 3, _d, string_height("Ay"), 150);        }    }    this.get_value = function(box_id, target) {        var _data = {}        for (var i = 0; i < array_length(this.box); i++) {            if ((this.box[i])._id == box_id) {                _data = this.box[i];                break;            }        }        switch (target) {            case "pos_x" : return _data.pos_x;            case "pos_y" : return _data.pos_y;            case "width" : return _data.width;            case "height" : return _data.height;            case "title" : return _data.title;            case "desc" : return _data.desc;            case "state" : return _data.state;            case "pict" : return _data.pict;            case "_id" : return _data._id;        }    }    this.get_length = function() { return array_length(this.box); }    this.get_ids = function() {        _arr = []        for (var i = 0; i < array_length(this.box); i++) {            array_push(_arr, (this.box[i])._id);        }        return _arr;    }    return this;}

Because when I tried to use it, it just returns this error.

ERROR in action number 1of Create Event for object obj_ach_manager:Variable <unknown_object>.this(100048, -2147483648) not set before reading it. at gml_Script_anon@95@tooltip@tooltip (line 9) -       this.box = [];gml_Script_anon@95@tooltip@tooltip (line 9)gml_Object_obj_ach_manager_Create_0 (line 2) - t.__init__();

Viewing all articles
Browse latest Browse all 189

Trending Articles