GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Script Submission » array_sort » 2013-06-26 06:28:38

NicharCZ
Replies: 0

Hi all,
this code sort the 2D array by first column:

Expand//array_sort(input,output,rows,columns,ascending)
// Created by NicharCZ
// 

var a, b, c, d, e, n, m, z;
a=argument0;
b=argument1;
n=argument2;
m=argument3;

_list=ds_list_create();

for (i=0; i<n; i+=1) {
    _temp[i]="";
    z=0;
    repeat (m) {
        _temp[i]+=string(variable_local_array2_get(a,i,z))+"|";
        z+=1;
    } 
    _temp[i]=string_delete(_temp[i],string_length(_temp[i]),1);
    ds_list_add(_list, _temp[i]);
}

ds_list_sort(_list,argument4);

for (i=0; i<n; i+=1) {
    _temp[i]=ds_list_find_value(_list,i);
    c = string(_temp[i]) + "|";
    e=0;
    repeat (string_count("|",c)) {
        f = string_pos("|",c)-1;
        variable_local_array2_set(b,i,e,string_copy(c,1,f));
        c = string_delete(c,1,f+1);
        e+=1;
    }    
}

ds_list_destroy(_list);

Input:

Expanddata[0,0]="3:15:47"   data[0,1]="Paul Rayon"          data[0,2]="LDD"  data[0,3]=1
data[1,0]="3:10:58"   data[1,1]="Raoul Puyerredon"    data[1,2]="NCS"  data[1,3]=2
data[2,0]="3:14:29"   data[2,1]="Fabian Hoffnung"     data[2,2]="LDD"  data[2,3]=3
data[3,0]="3:13:35"   data[3,1]="Georgios Lalaounis"  data[3,2]="NCS"  data[3,3]=4
data[4,0]="3:11:34"   data[4,1]="Andre Verge"         data[4,2]="LDD"  data[4,3]=5
data[5,0]="3:15:48"   data[5,1]="Manuel Rapidas"      data[5,2]="NCS"  data[5,3]=6

Output:

Expanddata[0,0]="3:10:58"   data[0,1]="Raoul Puyerredon"    data[0,2]="NCS"  data[0,3]=2
data[1,0]="3:11:34"   data[1,1]="Andre Verge"         data[1,2]="LDD"  data[1,3]=5
data[2,0]="3:13:35"   data[2,1]="Georgios Lalaounis"  data[2,2]="NCS"  data[2,3]=4
data[3,0]="3:14:29"   data[3,1]="Fabian Hoffnung"     data[3,2]="LDD"  data[3,3]=3
data[4,0]="3:15:47"   data[4,1]="Paul Rayon"          data[4,2]="LDD"  data[4,3]=1
data[5,0]="3:15:48"   data[5,1]="Manuel Rapidas"      data[5,2]="NCS"  data[5,3]=6

#2 Re: Script Submission » instance_variable_controll » 2011-07-20 06:57:30

Well, i show you some example:

I have swiching with buttons. If I click the first button, variable global.mode=1, if I click the second button, variable global.mode=2 etc.. And other object can exists only if global.mode=1.. With my script, you can select position of instance, object, variable and value itself.

#3 Script Submission » instance_variable_controll » 2011-07-19 09:15:43

NicharCZ
Replies: 2

Hi there smile
I've created some script during making on my game. This scripts controll the existence any instance in room dependence on some variable: it means, the instance can exist, only, if selected variable has current value. If not, the instance will be destroyed. Look at code and than understand. smile

Expand//instance_variable_controll(object,x,y,variable,value)
// Create by NicharCZ
// Copyright 2011
//
//

var obj, variable, value, xx, yy;
obj=argument0
xx=argument1
yy=argument2
variable=argument3
value=argument4

if variable==value && !instance_exists(obj) {
    instance_create(xx,yy,obj)
    }
if variable!=value {
    if (instance_exists(obj)) { 
       with (obj) 
       instance_destroy()
       }
    }

I'm sorry for my english, that's really tragic smile
Edits: Correction

Board footer

Powered by FluxBB