Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / There's got to be a better way than this

Author
Message
Blue Steel AU
AGK Developer
16
Years of Service
User Offline
Joined: 22nd Aug 2007
Location: Bundaberg, Qld, Australia
Posted: 19th Dec 2018 06:00 Edited at: 19th Dec 2018 06:04
here is the code I'm working on and I'm having to enter the data manually in the variable types to rebuilt a data file if it doesn't exist for any reason.

read my code and the com,men's to see if there's a better way for me to do what I'm trying to do if there isn't then it's going to be huge with over 255 object[number] type data blocks that I'll have to pit in ,. if there were data and read and restore statements I wouldn't have to do it this way I'd just have like data statements of at least 255 lines (none line of data as opposed to like at the moment I have 8 lines per item.. unless I'm missing something

BTW this is a fairly good example I hope of how to use arrays and types , file load and save, and the new way arrays can work. it checks for the file in the default area for the platform your working for. eh: in windows its different to iOS etc.. so no file paths are being used.
also the way I have it the .dat file it generates is harder to hack/change than a .txt file
I'm rather pleased with what I've done in less than 24 hours

please let me know if I can do it any better (smaller lol less code)

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Dec 2018 08:08
I see you're from god's country. Home of the black gold!

I think your code is tailor made for a json file.

Try this;
1. Remove the references to the data file open/read etc
2. After you have loaded your array with data, which you do in lines 40 thru 56
3. Add this line object.save("objects.json")

Then when you run your program again at the very beginning you can say
objects.load("objects.json")

If you look in your write media directory (C:\Users\your_id\AppData\Local\AGKApps\your_appname\media)
you will see your objects.json file

Rather than referencing the array all the time you can fill a data type then insert it into the array like this;
o as obbject
o.name$ = "BlueSteelAU"
o.type$ = "Player"
o.sheetxpos = 0
o.sheetypos = 0
o.sizex = 64
o.sizey = 64
o.maxhealth = 255
o.ability$ = "teleport"

then add that to the array like so;
object.insert(o)
Blue Steel AU
AGK Developer
16
Years of Service
User Offline
Joined: 22nd Aug 2007
Location: Bundaberg, Qld, Australia
Posted: 19th Dec 2018 09:28
thanks for the input.

I'm trying to make it not easy for them to edit it. without knowing what they are doing.
so I'm not after a .txt or .json file.

also the bit I'm complaining about isn't the loading and saving of the file. it's setting up all the default values for over 255 items/mobs etc.. the reading and writing of them is ok. just putting all the defaults in.

kool I didn't know about the object insert and that way of doing it.

I'll seriously consider and try out what you've said thanks

eventually I'll also release a object data editor (kinda like a small database program..

I need the manually resetting of the data in case something happens to the data file saved on where they are playing. (I guess I could actually do away with the external file all together but then it wouldn't as easily extendable/modifiable
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 19th Dec 2018 13:06
Id consider using a combination of saving JSON files as well as using string tokens for setting up the raw data

You dont need to save in json format and can use your serialisation using WriteString,integer etc and just use string tokens to set up the data if you want to

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Dec 2018 14:51
Saving the data in a raw binary format would not only load faster than parsing a text document, it'd also make it harder for someone to hack the values without knowing the structure of the file. You could also encrypt the file.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Dec 2018 19:32
Ok so if im reading you right you want the defaults embedded in your code. You have the defaults in a file right now that you can load.
I would write a proggy to read the file and write out source code lines to initialize your object.
Make it a separate .agc file and include it in your main proggy.
Blue Steel AU
AGK Developer
16
Years of Service
User Offline
Joined: 22nd Aug 2007
Location: Bundaberg, Qld, Australia
Posted: 19th Dec 2018 23:57
nah I don't have the defaults, this was a project that I was working on in blitzbasic (the original) way back in the days of old but I've since lost the source code, I think I still have the graphics sheet from it somewhere. so I know that there were over 255 items / monsters etc.
attached is how the code stands at the moment thanks to all .. and I've cleaned it up , and fixed the extra blank entry from being written and displaying the correct number of objects now in the object count too. also made it now only load the days if it hasn't just been re-created, and moved the displaying of the objects out to its own function.added a new global variable fields instead of hard coding the number which means that I don't have to count them.. lol the value is worked out by now many , in first entry of the data. and other little usability tweaks

all in all its a lot better and more manageable now thanks to making a string of all the data , more like a data statement again .. tyvvm



Login to post a reply

Server time is: 2024-04-26 17:38:44
Your offset time is: 2024-04-26 17:38:44