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.

AppGameKit Classic Chat / Help with arrays (sorry)

Author
Message
Arynderquane
12
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Hell
Posted: 14th Oct 2011 00:45
i really need to define an array inside a type, but he says i can't.
Really, pls help me finding a way.
The problem is like this:

TYPE weapon
dim bullets[50]
ENDTYPE

i need to access weapon.bullets[0] for example, and i want to create 10000 weapons, so i can't create a bullet array for each weapon: i have to add it into the type.

Any idea?
XanthorXIII
AGK Gold Backer
12
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 14th Oct 2011 01:32
Right now you cannot define Arrays within Types. I know it's kinda PITA at the moment. Lee is working on that so we can have it.

10,000 weapons sounds pretty ambitious. How about something smaller like 5-6 Weapons so you can get a system in place and then expand upon that later on? It's easier to start small and then ramp up.
Set goals that you can meet.
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 14th Oct 2011 02:05
10,000 weapons each having its own bullet array with 51 elements? Like Xanthor said that's ambitious. I'd look into tier 2 for this one.

Arynderquane
12
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Hell
Posted: 14th Oct 2011 02:35
i'd like too, but in free trial tier 2 isn't included.
10.000 was just a random high number, i meant that i cannot define an array for each instance of the variable, i have to include in the type.
Btw 6 or 10k weapons, it's just a "for" condition that meets the requirement

And above all, 10k weapons no, but 500 bullets can happen they need to be displayed all at once. I need an array system to track them all. Well, the truth is that i need a LIST system, but lists don't exist as far as i know.

Is there some tier 2 tutorial out, so i can see the complexity?
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 14th Oct 2011 06:40 Edited at: 14th Oct 2011 06:48
Quote: "Btw 6 or 10k weapons, it's just a "for" condition that meets the requirement"

On the outside but it is a lot more operations for the processor to handle and it could impact performance depending on what you're doing inside that for loop.

Quote: "
Is there some tier 2 tutorial out, so i can see the complexity?"

Not that I know of but there are examples. As for complexity, the commands themselves are the same.

agk:: Print("Hello World"); in tier 2

does the same as

Print("Hello World") in tier 1

So tier 2's complexity depends a lot on your knowledge of C++ which is safe to say, a lot more complex than Tier 1. But here's a little example of how you'd accomplish your goal in tier 2.



This outputs:
1
Press any key to continue . . .

NOTE: The above doesn't use any AppGameKit commands.

Arynderquane
12
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Hell
Posted: 14th Oct 2011 11:23
(inside the for loop it's safe just to create 10k instances of weapon)

That's great that the commands are the same!
Well, i born as a c++ programmer, that's why i was asking.
I definitely prefer programming in c++ rather than basic, for OO (object oriented), flexibility and performances.
I'm just sad that i downloaded AppGameKit yesterday and in a few hours i developed a working snake clone but i can't try this speed on tier 2 version

Since i DO believe in c++ and AppGameKit, i'm sure that performances are safe, even without a tryout.

Thanks a lot.
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 14th Oct 2011 13:54
Quote: "Well, i born as a c++ programmer, that's why i was asking."

You with held that information. You can probably tell that I'm not terrific at C++, I've got a lot to learn but I'm getting there.

Quote: "
Since i DO believe in c++ and AppGameKit, i'm sure that performances are safe, even without a tryout."

Well it certainly shouldn't be worse than AppGameKit BASIC.

TGC provide a template which you can use as well so it's just a matter of using the template, linking up your libraries and away you go.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Oct 2011 14:44
What about:


That way you have up to five weapons with up to 500 different bullet types. IE. wepaon[3,20].ammo would tell you how much ammo type 20 was left for weapon 3.

Seems a bit odd why you'd want that many ammo types but...

Arynderquane
12
Years of Service
User Offline
Joined: 13th Oct 2011
Location: Hell
Posted: 14th Oct 2011 16:34
"i was born as c++ programmer" doesn't mean that when i came to the world my 1st word was "compile", i meant that when i started programming, chronologically my 1st language learned was c++, my second basic, my 3rd java. I studied it at university and i programmed a flipper with SDL for an exam, so i should be able to use the tier 2
Obviously i barely reach the 5% of all c++ existing libraries, but i think that's enough for using AppGameKit
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 14th Oct 2011 23:46
@ Baxslash: That's a good idea except what if you wanted two or more arrays within your type?

Quote: "i was born as c++ programmer" doesn't mean that when i came to the world my 1st word was "compile", i meant that when i started programming, chronologically my 1st language learned was c++,"

I took it as "I really love c++" and it seems you do so have fun with tier 2.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Oct 2011 01:25
Quote: "Baxslash: That's a good idea except what if you wanted two or more arrays within your type?"

Not sure what you mean Hodgey?

I'm just giving an example how to simulate what @Arynderquane wanted to do. Multi-dimensional arrays can do most of what might be needed for this kind of data storage.

When you are spoiled by OOP it makes 'basic' languages seem primitive but OOP just makes what is already possible easier and more obviously structured.

C++ is not actually a genuinely object oriented language but it can be used in that way...

Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 15th Oct 2011 01:55
Quote: "Not sure what you mean Hodgey?"

Something like this


Quote: "I'm just giving an example how to simulate what @Arynderquane wanted to do. Multi-dimensional arrays can do most of what might be needed for this kind of data storage."

I know Baxslash but on the chance he wanted to extend it further such as my example, how would you do it?

LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 15th Oct 2011 06:48
When the time comes I will be looking at adding static arrays to types:

TYPE weapontype
active as integer
bullets[50] as integer
ENDTYPE
dim weapon[10] as weapontype
weapon[5].bullets[25]=42

In the meantime, some simple word play can achieve the same readable code with the current AppGameKit compiler:

TYPE weapontype
active as integer
ENDTYPE
dim weapon[10] as weapontype
dim weapon_bullets[10,50] as integer
weapon_bullets[5,25]=42

I drink tea, and in my spare time I write software.
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 16th Oct 2011 05:28
Quote: "When the time comes I will be looking at adding static arrays to types"

That's good to hear Lee.

Does AppGameKit support pointers? If it does then that gives me an idea on a potential work around.

LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 18th Oct 2011 02:02
We support pointers in Tier 2 (C++) of course, but there are no plans to add pointers to T1 (BASIC). We have been talking blue sky about possible solutions for referencing data, but nothing has really settled in as a great complimentary AppGameKit feature.

I drink tea, and in my spare time I write software.
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 18th Oct 2011 06:48
Thanks Lee, I guess if you wanted to use pointers then you'd probably use Tier 2 anyway.

3d point in space
14
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 21st Oct 2011 04:13
I use a rotating method approch too this problem, and found a suitable solution useing code. I have a weapon equiped array which is a 12 slot array. I also include a larger array to store the weapons in a struct format. I am currently doing the same thing but the code all is in teir 2.
first you need to see if the weapon is equiped.

Then reset the bullet data by checking if it is equiped

check if the rate of fire is greater then a number.

then place the bullet using sin or cos.

store some information about the speed and the angle fired

increment the life of the bullet

player.g_bullets[xxb][yyb].active is true

increment the data of each bullet

Check to see if it hits a wall or enemy. If this is true then reset the data of the missle.

The stuct that contains the information is in a player struct.

The array i used to look for equiped weapons is a 12 in length

the bullets that i used are stored in the player struct which there is a array of 80 by 20 this stores all the copys of the bullets and weather are not they are active.

Go through yourself at a wall.
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 21st Oct 2011 06:15 Edited at: 21st Oct 2011 06:16
Quote: "I am currently doing the same thing but the code all is in teir 2. "

Unfortunately, tier 1 isn't as obviously flexible as tier 2.

Quote: "player.g_bullets[xxb][yyb].active is true"

See this, in that exact format, is currently impossible in tier 1. But there might be a work around which I'm going to write down now so I don't forget it. This is for tier 1 and is currently all theory as I haven't tested it out.

Let's say you want this:

But of course the above won't compile. So what we could do is use an external array with one extra dimension (to use as a reference number) compared to the array you want inside your type. So something like this:

Note that the first dimension of 'bullets' has the same amount of instances as the 'guns'. We can now make a reference variable in our type. So something like this:


Ok all of this is just theory that was in my head and I needed to get it in digital form. Remember you'll need to handle your reference numbers carefully. And a thanks to baxslash.

3d point in space
14
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 22nd Oct 2011 02:18 Edited at: 22nd Oct 2011 02:19
Hodgey that is exactly what i do expect
the two dimesional array has copys of all the bullets and the type of bullets just like you said.
And i have another array just like you said that keeps track of what the player is equiped with.
exp.
[0,-1,-1,0,-1,-1] would mean that you currently have two weapons equiped of type 0, and -1 means the bullets dont fly diagnal and there not equiped.

This will look into the two dimesional array and based apon the infromation given will fire bullets of type 0.

Go through yourself at a wall.

Login to post a reply

Server time is: 2024-04-24 20:19:21
Your offset time is: 2024-04-24 20:19:21