• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How to make a system that take files from the game directory for easier coding

L

Linkdeous

Guest
Hello, i'm currently trying to make a game where there is a lot of gun, and i wanted to know if there was any way to make a system like in Starbound for exemple, where creating a folder, making a image and putting in it and then modify a very simple code make a new gun in the game was possible in GML.

What i would like to do is just make this array easier to access and to create new entry

GUN NAME | SPRITE NAME | FIRE RATE | DAMAGE | PROJECTILE

the user would just have to use a pre-made text code, and then simply changes values to make new guns. is it possible ? also, i dunno but if it could be added in a certain array it would be the best :)
 
F

Frolacosta

Guest
Just to clarify, are you wanting the information of the gun (name, fire-rate, etc) to be stored in an external file, which the player can modify themselves?
 

PlayerOne

Member
Hello, i'm currently trying to make a game where there is a lot of gun, and i wanted to know if there was any way to make a system like in Starbound for exemple, where creating a folder, making a image and putting in it and then modify a very simple code make a new gun in the game was possible in GML.

What i would like to do is just make this array easier to access and to create new entry

GUN NAME | SPRITE NAME | FIRE RATE | DAMAGE | PROJECTILE

the user would just have to use a pre-made text code, and then simply changes values to make new guns. is it possible ? also, i dunno but if it could be added in a certain array it would be the best :)
Yes this is possible. However it's going to take a little effort considering the work it takes just to import a sprite alone.

For example:
Code:
var sprite_weapon;
sprite_weapon = get_open_filename("png|*.png", "");
if sprite_weapon != ""
   {
  sprite_add(sprite_weapon, imgnumb, removeback, smooth, xorig, yorig);
   }

//^^^^^This will add a sprite and put int the variable sprite_weapon.
This is just some example code I took from the docs and modified for your question. Not 100% sure it will work but it should give the basic idea.

As for imputing weapon stats that one is tricky. You would have to modify one of those RPG tutorials you find online that allow you to input a custom name. Except the code I posted below doesn't use characters and only reads/accepts numbers. There might be a bug due to the string length, but it works.

Code:
CREATE EVENT:
max_width=150 / 3
selected=false;
blink=false
text=""
alarm[0]=30
can_click=false
Code:
STEP EVENT:
var number;

if (selected==true)
{
 
if string_width(keyboard_string) < max_width //Max Characters
{
 
text=keyboard_string
number = real(keyboard_string)
global.rate_of_fire=number
}
else
{
 
keyboard_string=text 
 
}
 
 
 
}
Code:
Alarm[0]:

if (blink==false)
{
blink=true
}
else
{
blink=false 
}
alarm[0]=30;
Code:
DRAW EVENT:

draw_self()
var XX = sprite_width / 2 - 20
draw_set_font(font_FreesiaUPC)
draw_set_color(c_lime)
draw_set_halign(fa_left)
draw_set_valign(fa_center)


if (text="") && selected==false
{ 
draw_text(x+-XX,y,"Rate of fire")

}

else
{
 
   if (blink==false) || (selected==false)
   {
   draw_set_color(c_white)
   draw_text(x+-XX,y,text);
   }
   else
   {
   draw_text(x+-XX,y,text+"|");
   } 
 

}
Code:
LMB Pressed:

selected=true;
keyboard_string=text;
 
L

Linkdeous

Guest
Wow, that a lot of code here , as to clarify what it would look like is this :

you have a certain folder, with item in it, and you can add item by taking another already existing gfolder and modify it : i took a starbound mod that add gun to show you :

inside the text file is this :
{
"itemName" : "accatranlaspistol",
"price" : 960,
"inventoryIcon" : "accatranlaspistol.png",
"maxStack" : 1,
"rarity" : "common",
"description" : "An Accatran-Pattern laspistol.",
"shortdescription" : "Accatran Laspistol",
"level" : 1,
"tooltipKind" : "gun",
"weaponType" : "Pistol",
"itemTags" : ["weapon","ranged","pistol"],
"twoHanded" : false,
}

I removed LOT of the code, as it was about crafting and scripting the gun, thign that i don't really need, but that's just to show a exemple. What the game would do is then take that parent folder, and then add everything that add gun to the game. is it possible in any way ?
 

PlayerOne

Member
Wow, that a lot of code here , as to clarify what it would look like is this :

you have a certain folder, with item in it, and you can add item by taking another already existing gfolder and modify it : i took a starbound mod that add gun to show you :

inside the text file is this :
{
"itemName" : "accatranlaspistol",
"price" : 960,
"inventoryIcon" : "accatranlaspistol.png",
"maxStack" : 1,
"rarity" : "common",
"description" : "An Accatran-Pattern laspistol.",
"shortdescription" : "Accatran Laspistol",
"level" : 1,
"tooltipKind" : "gun",
"weaponType" : "Pistol",
"itemTags" : ["weapon","ranged","pistol"],
"twoHanded" : false,
}

I removed LOT of the code, as it was about crafting and scripting the gun, thign that i don't really need, but that's just to show a exemple. What the game would do is then take that parent folder, and then add everything that add gun to the game. is it possible in any way ?

When I wrote that code I figured you would import the weapon sprite in a custom weapon menu in-game, not in a folder. I've actually had a similar concept when it came to importing music in-game. My only reasonable idea would be to have separate groups of variables (slot1,slot2,etc) and folders. Then you would have to import a *.ini that has the stats and a sprite in the same folder to get the desired results. No different than saving/loading on a menu screen.

Now to be clear if you are asking if it's possible to add folders and have the game run a scan for new folders on start-up. I have no idea.
 
L

Linkdeous

Guest
yeah that's what i'm searching for, i didn't knew if there is a way to scan folder and stuff, thanks for the lead i gonna continue searching
 
L

Linkdeous

Guest
Thanks a lot, gonna try this later, at school rn , thanks a lot
 
Top