Magicwaterz
Member
Hello, I'm currently making a game similar to Bookworm Adventures and I've already set up the basic attacks. I am now trying to add code that basically checks what attacks it contains.
So, these are the variables where it gets its attacks:
And this is the code I tried to get values:
And an example as how it is used
Now this seem to work for now but I don't want to repeatedly use the string_pos() block of code in the script just to get the sprites I wanted when used.
I just want to know if there's anyway I can make the script smaller wherein I can.
1) Return the string of the attack name (So that "[Att,3]Damage" will only return "Damage")
2) Return the string of the attack type so that it can identify what sprite to use (So that "[Att,3]Damage" will return "Att" and it will assign a sword sprite)
3) Return a value from the attack type, so that it can assign how much damage it deals ("[Att,3]Damage" will return a damage value of 3) ;
or assign the number of objects to be affected and how long it lasts ("[Sms,6,2]Smash Tiles" will return a value of tiles = 6 and turns = 2)
4) Able to segragate the attack types ("[Att,3|Sms,2,3|Chr,2,3]Char and Smash" are all different and should return "Att" with 3, "Sms" with tiles = 2 and turns = 3, and "Chr" with tiles = 2 and turns = 3)
I know this all too much to ask so a nice easy to understand terms and step is of great help as I only know coding up to a surface level. And I am using GMS 1.4 by the way.
So, these are the variables where it gets its attacks:
Code:
///Attack Lore
AttackLore[0] = "[Att,3]Damage";
AttackLore[1] = "[Fir,1]Fire Tile";
AttackLore[2] = "[Att,3|Sms,2,3|Chr,2,3]Char and Smash";
AttackLore[3] = "[Att,2|Fir,4]Fiery Lineup";
AttackLore[4] = "[Sms,6,2]Smash Tiles";
Code:
///scr_get_StatLore(exclude character, string, getLore);
var a, b, c;
a = argument0;//characters enclosed to get the string
b = argument1;//the string used
c = argument2;//which data to retrieve
//d = argument3;
var AttLore = ds_list_create();
var AttString = "";
var AttTurn = ds_list_create();
var AttAmnt = ds_list_create();
var chkOpen = string_char_at(a, 1);
var chkClose = string_char_at(a, 2);
//get Attack Lore String
var extractLore = string_copy(b, string_pos(chkClose, b) + 1, string_length(b) - string_pos(chkClose, b));
AttString = extractLore;
//add attacks to a list
var extractAttacks = string_copy(b, string_pos(chkOpen, b) + 1, string_pos(chkClose, b) - 1);
if string_pos("Att", extractAttacks) != 0 {
ds_list_add(AttLore, 0);
}
if string_pos("Fir", extractAttacks) != 0 {
ds_list_add(AttLore, 1);
}
if string_pos("Chr", extractAttacks) != 0 {
ds_list_add(AttLore, 2);
}
if string_pos("Sms", extractAttacks) != 0 {
ds_list_add(AttLore, 3);
}
//extract values
switch(c) {
case 0: return AttLore; ds_list_destroy(AttLore); break;
case 1: if AttString != "" {return AttString} else {return "<MISSING_VALUES!>"}; break;
//case 3: return AttTurn; break;
//case 4: return AttAmnt; break;
default: return "<MISSING_VALUES!>"
}
ds_list_destroy(AttTurn);
ds_list_destroy(AttAmnt);
Code:
var getUnit = obj_Enemy;
var yy = 0;
var xx = 0;
//Draw text
for (var a = 0; a < array_length_1d(getUnit.AttackLore); a++) {
draw_sprite(spr_LoreBorder_Att, 0, room_width - 196, (room_height div 2) + 96 + yy);
var getBW = (sprite_get_width(spr_LoreBorder_Att) / 2) - 16;
var getStr = scr_get_StatLore("[]", getUnit.AttackLore[a], 1);
var getIco = scr_get_StatLore("[]", getUnit.AttackLore[a], 0);
draw_set_font(fnt_AttackLore);
//Draw text
for (var b = 0; b < ds_list_size(getIco); b++) {
var multi = false;
if ds_list_size(getIco) != 1 {
multi = true;
}
switch(getIco[| b]) {
case 0:
if multi == false {
draw_sprite(spr_AttackIcons, 0, room_width - 196 - getBW + xx, (room_height div 2) + 96 + yy);
}
else
{
draw_sprite_ext(spr_LoreBorder_Att, 1, room_width - 196, (room_height div 2) + 96 + yy, 1, 1, 0, c_white, 0.5);
xx -= 32;
}
;
break;
case 1: draw_sprite(spr_AttackIcons, 1, room_width - 196 - getBW + xx, (room_height div 2) + 96 + yy); break;
case 2: draw_sprite(spr_AttackIcons, 2, room_width - 196 - getBW + xx, (room_height div 2) + 96 + yy); break;
case 3: draw_sprite(spr_AttackIcons, 3, room_width - 196 - getBW + xx, (room_height div 2) + 96 + yy); break;
}
xx += 32;
}
var getdef = string_height(getStr);
var getHt = string_height_ext(getStr, -1, 312);
draw_text(64, 64 + yy, getHt);
draw_text_ext_transformed(room_width - 156, (room_height div 2) + 96 + yy, getStr, -1, 312, getdef / getHt, getdef / getHt, 0);
xx = 0;
yy += 32;
//Draw Icons
}
I just want to know if there's anyway I can make the script smaller wherein I can.
1) Return the string of the attack name (So that "[Att,3]Damage" will only return "Damage")
2) Return the string of the attack type so that it can identify what sprite to use (So that "[Att,3]Damage" will return "Att" and it will assign a sword sprite)
3) Return a value from the attack type, so that it can assign how much damage it deals ("[Att,3]Damage" will return a damage value of 3) ;
or assign the number of objects to be affected and how long it lasts ("[Sms,6,2]Smash Tiles" will return a value of tiles = 6 and turns = 2)
4) Able to segragate the attack types ("[Att,3|Sms,2,3|Chr,2,3]Char and Smash" are all different and should return "Att" with 3, "Sms" with tiles = 2 and turns = 3, and "Chr" with tiles = 2 and turns = 3)
I know this all too much to ask so a nice easy to understand terms and step is of great help as I only know coding up to a surface level. And I am using GMS 1.4 by the way.