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 / User Defined Data types. General programming question.

Author
Message
Thomas John Gorham
5
Years of Service
User Offline
Joined: 23rd Jun 2018
Location:
Posted: 30th Sep 2020 13:17
Hey guys,

Been working again a bit on my 2D shooter.

Ive gotten to the stage where I am putting multiple different types of enemies and projectiles on the screen at once.

At the moment I have been copying and pasting code each time I create a new enemy or projectile, and I just go through the code with the Find and replace function and replace all the old names with the new.

Now I know this isn't what I should be doing. I feel the whole point of using UDTs correctly would be you just use the one set of code for all projectiles, and stop copying and pasting and rewriting everything.

If someone could go through my code here I would be very grateful. Sorry its over a 1000 lines. I think if you jump to the projectiles function you will see a good example of what Im trying to say. I have basically copied and pasted all the code for bullets and relabeled it rockets. And it works but I'm sure there is a better way as the bullets and rockets both share the same UDT (projectiles).

Anyway I hope the question is clear enough.

Thanks in advance.







Lokto
FPSC Reloaded TGC Backer
4
Years of Service
User Offline
Joined: 19th Sep 2019
Location:
Posted: 30th Sep 2020 17:27
Create a mob array. I added a name field and changed the last field to "attack2". Change it to whatever generic field you need to repurpose among your mobs. Or add more fields. Whatever the case, putting it in an array should help manage your mobs better than separate UDTs for each.


Lupo4mica37
3
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 30th Sep 2020 19:41 Edited at: 30th Sep 2020 20:02
You know what else you could do building upon what Lokto suggested. You could create a txt file with a list of the attributes for all your entities and then create a for next loop to read the data from the file directly into each respective database for each entity. It would be good to add an extra type to account for the mob_number, so that you can keep track which entity is of what number.

????????
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 1st Oct 2020 06:35
Hi,
You can also if you have such a UDT as Lokto suggests. Just load the data with a JSON file.
If you are not so fit with the structure of a JSON file. I recommend to create and save an array with the UDT so you have a basic structure that you can fill with data.

This could look like this


You can add new mobs with Copy/Paste.
When you have filled your data you can now convert the write routine into a read routine.



The saved json file can be found in '%USER%/AppData/AGKApps/%PROJECT_NAME%/media'.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Lupo4mica37
3
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 1st Oct 2020 17:29
Hi MadBit, could you send a link to more info about JSON files and how to use them in AppGameKit? The .tojson & .fromjson are actual commands, right? Would be good to learn more about this.
????????
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 1st Oct 2020 20:06
I only know what is written in the documentation. (At the bottom of the site)
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Lupo4mica37
3
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 1st Oct 2020 22:20
Awesome! That is what I was asking for. Danke.
????????
Lupo4mica37
3
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 1st Oct 2020 22:52
I just tested this, and it is amazing. It makes me reason to change the current system of storing data for the sprite shapes to a json file instead. It looks much more clearer the data in a json file. Really good to learn about this.
????????
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 2nd Oct 2020 05:51 Edited at: 2nd Oct 2020 05:52
Quote: "Sorry its over a 1000 lines. I think if you jump to the projectiles function "

i won't bother with 1000 lines of code but Lokto's advice is solid.

And, i fail to understand the need to build upon it or use files to populate the mobs/projectiles vs creating a couple of functions to fill/handle data in the array(s).

it seems the OP's inquiry was taken for a ride (IE, off topic), or did i miss something?
[My Itch.io Home] [#LowRezJamAGK2020]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=AGK] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[Google Forum Search]
Thomas John Gorham
5
Years of Service
User Offline
Joined: 23rd Jun 2018
Location:
Posted: 2nd Oct 2020 10:47
Yes thanks everyone for your different advices.

I will look into JSON files but I think its something a little different to the code lesson im looknig for.

An array of every enemy, and an array of every projectile, that seems to be the right way to go. At the moment I have an array of Zombies, an array of dogs, etc. Ill try to combine it into the one.

Side question, Is it possible to have an array without a defined length of entries?

Can you make an array bigger or smaller on the fly?

Or is it normal practice to just make them bigger than what should be necessary (i.e. having a creature that spawns other creatures, if it was stored in an array and then got larger than the arrays defined length? )

Sorry ive never programmed outside of AppGameKit and Darkbasic so these concepts are very new to me (I dont even know what a JSON file is lol, but ill look hard at it)
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 2nd Oct 2020 11:00 Edited at: 2nd Oct 2020 11:01
Quote: "Side question, Is it possible to have an array without a defined length of entries?
Can you make an array bigger or smaller on the fly?"


Yes.
You can define an array as
array as int[]

Then;
array.insert(25) // Will Add 25 to the end of the array

array.length = 5 // Will set the array's length to 6 values. Indexes 0 thru 5

There are other functions you can use with arrays as well

Take some time and read this guide to find out exactly how you can work with arrays
Thomas John Gorham
5
Years of Service
User Offline
Joined: 23rd Jun 2018
Location:
Posted: 2nd Oct 2020 12:17
What about an array of a user defined data type? Can it also have an undefined length?

Say

type enemy
x as intger
y as integer
attack as integer
endtype

Enemyarray[] as enemy

MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 2nd Oct 2020 12:53
Quote: "having a creature that spawns other creatures, if it was stored in an array and then got larger than the arrays defined length?"


The JSON file is more of a template or blueprint for your bullets/mobs. By first defining the rough properties. So for your rockets for projectiles of various types that differ in speed and damage. Players and monsters that also differ in life energy and damage.

When you finally use a projectile, you only make one copy of the blueprint and then update the copy only with the data that changes. The position for example.
These copies should then be managed in other arrays.

This could look like this (pseudo code)

global mi as mobinfo[]
// load json in mi array

global allmobs as mobinfo[]
//to spawn a new mob, copy a template to allmobs. Assuming a zombie is defined in mi in index 2
allmobs.insert(mobinfo[2])
// now set current life data. set start position for example.

// later
// update mobs
for i=0 to allmobs.length
// update position and other things.
next


I hope you understand roughly what I mean.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 2nd Oct 2020 21:12
Quote: "What about an array of a user defined data type? Can it also have an undefined length?"


Yes. As the documentation describes.

Read the documentation
Lupo4mica37
3
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 2nd Oct 2020 23:34
Quote: "And, i fail to understand the need to build upon it or use files to populate the mobs/projectiles vs creating a couple of functions to fill/handle data in the array(s). "


That's a good point.

Quote: "it seems the OP's inquiry was taken for a ride (IE, off topic), or did i miss something?"


I don't know my friend, it's the Game Creators forum, it's all about programming, right?

I will never stop to help people in whatever way I can in my limited knowledge of programming just to help them in the present moment, despite there are people more qualified than me to help them like yourself and MadBit and blink0k. I am sure Lee would agree 777%. I respect everyone and I am honest to the face. I couldn't care less about consequences, when my own great grandfather suffered in Dachau. I am here to help, that is my job. We take for granted the help of others, where we really ought to be greatful that there are people willing to help, don't you agree?

I learn so much from you people when you go off topic in the realm of programming. This is the whole point of this forum, to help each other become better programmers, to find better solutions to the same problems.

Thank you for all your input, it really means a lot.
????????
Thomas John Gorham
5
Years of Service
User Offline
Joined: 23rd Jun 2018
Location:
Posted: 3rd Oct 2020 03:04
Hey guys this question is also going to sound stupid

Quote: "Yes. As the documentation describes.

Read the documentation"


I bought AppGameKit studio through steam, and I'm finding the documentation difficult to navigate compared to darkbasic from wayyyy back.

There used to be examples and stuff that would copy to the editor when you clicked on them.

Like when I click example and then click on the space game, I scroll through it and cant find the actual code? Am I supposed to download these examples externally? Where are they?
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 3rd Oct 2020 03:31 Edited at: 3rd Oct 2020 03:32
AGK Resources

I highly recommend the small games templates

Also there is a command search if you're looking for something more specific

The installed AppGameKit will contain example projects here C:\Program Files (x86)\The Game Creators\AGK2\Projects. You will need to copy them out of the Program Files folder in order to use them
Thomas John Gorham
5
Years of Service
User Offline
Joined: 23rd Jun 2018
Location:
Posted: 3rd Oct 2020 05:57
Thanks Blinkok.

Great succinct advice. Ill definately spend the next few weeks scrolling through all of these suggestions.

Login to post a reply

Server time is: 2024-04-19 05:39:39
Your offset time is: 2024-04-19 05:39:39