Game Maker Tips
CODES:
Timer Code (Suyo)
Easy setting of alarms
Explode Script (Suyo)
This takes a string and cuts it on a defined letter. Like if you have the string "to:Henry" and call this script with the limiter ":" it returns "to" and "Henry". Ignore the german comments.
Usage:
Create a script, name it explode_script and paste the code there. Now use in the code:
arrayname: Name of the array. Write in quotes (" or ')!
globalarray: 0 (false) for local, 1 (true) for global array
string: String to be split
delimiter: Where the string should be cut
löschen: 1 (true) or 0 (false). If true, it deleted the delimiter from the parts. If 0, the delimiter gets added to the previous part.
limit: How many parts should be there? 0 for unlimited parts.
--> Returns number of parts
Examples:
Returns:
TIPS:
Timer Code (Suyo)
Easy setting of alarms
- Code: Select all
alarm[0]=(SECONDS)*room_speed
Explode Script (Suyo)
This takes a string and cuts it on a defined letter. Like if you have the string "to:Henry" and call this script with the limiter ":" it returns "to" and "Henry". Ignore the german comments.
- Code: Select all
var arrayname,globarr,meinstring,teiler,loeschen,limit,meinstring2,vorkommen,sooft;
//Argumente zu Variablen
arrayname = argument0
globarr = argument1
meinstring = argument2
teiler = argument3
loeschen = argument4
limit = argument5
//wie oft kommt der Teiler im String vor
vorkommen = string_count(teiler,meinstring)
if (limit == 0 || vorkommen < limit) { //wenn Limit aus ist oder der Teiler weniger oft vorkommt als das Limit
sooft = vorkommen //vorkommen-mal "explodieren"
} else {
sooft = limit //limit-mal "explodieren"
}
if (vorkommen == 0) { //wenn es nie vorkommt, gleich so lassen
if (globarr == 1) {
variable_global_array_set(arrayname,0,meinstring)
} else {
variable_local_array_set(arrayname,0,meinstring)
}
return 0
exit
}
for (i=0; i<sooft; i+=1) {
meinstring2 = meinstring //Kopie anlegen
position = string_pos(teiler,meinstring) //wo ist der Teiler
if (loeschen == 1) { //wird der Teilere gelöscht?
meinstring = string_delete(meinstring,position,9999999) //Teiler und alles dahinter raus
} else {
meinstring = string_delete(meinstring,position+string_length(teiler),9999999) //alles hinter dem Teiler raus
}
if (globarr == 1) {
variable_global_array_set(arrayname,i,meinstring)
} else {
variable_local_array_set(arrayname,i,meinstring)
}
meinstring = string_copy(meinstring2,position+string_length(teiler),9999999) //meinstring beinhaltet nun den alten String ohne das Rausgeschnittene und Teiler
letzteid = i //der wievielte Durchlauf
}
if (meinstring == "" || meinstring == " ") {
return sooft //wenn alles weg ist, sind wir fertig
} else { //sonst muss noch der Rest it ins Array
if (globarr == 1) {
variable_global_array_set(arrayname,letzteid+1,meinstring)
} else {
variable_local_array_set(arrayname,letzteid+1,meinstring)
}
return sooft+1
}
Usage:
Create a script, name it explode_script and paste the code there. Now use in the code:
- Code: Select all
explode_script(arrayname,string,teiler,löschen,limit)
arrayname: Name of the array. Write in quotes (" or ')!
globalarray: 0 (false) for local, 1 (true) for global array
string: String to be split
delimiter: Where the string should be cut
löschen: 1 (true) or 0 (false). If true, it deleted the delimiter from the parts. If 0, the delimiter gets added to the previous part.
limit: How many parts should be there? 0 for unlimited parts.
--> Returns number of parts
Examples:
- Code: Select all
string1 = "rofl,lol,xD,wut,lmao,omfg"
string2 = "A-B-C-D-E-F-G"
string3 = "omnomnomnomnom"
string4 = "Delimiter:;with:;multiple:;characters"
return1 = explode_script("array1",0,string1,",",1,0)
return2 = explode_script("array2",0,string2,"-",1,3)
return3 = explode_script("array3",1,string3,"m",0,0)
return4 = explode_script("array4",0,string4,":;",1,0)
Returns:
- Code: Select all
array1[0]="rofl"; array[1]="lol"; ... ; array[5]="omfg"; array[6]=ERROR
return1=6
array2[0]="A"; array2[1]="B"; array2[2]="C"; array2[3]="D-E-F-G"
return2=4
array3[0]="om"; array3[1]="nom"; array3[2]="nom"; array3[3]="nom"; array3[4]="nom"
return3=5
array4[0]="Delimiter"; array4[1]="with"; array4[2]="multiple"; array4[3]="characters"
return4=4
TIPS: