Posted: 14th Oct 2011 0: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?
Posted: 14th Oct 2011 1: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.
Posted: 14th Oct 2011 2: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.
Posted: 14th Oct 2011 2: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?
Posted: 14th Oct 2011 6:40
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.

s 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.

+ Code Snippet
#include <iostream>
#include <cstdio>

class weapon {
public:
    int bullets[50]; // creates an array of 50 bullets, 0-49
};

int main() {
    weapon MyArray[10];
    
    MyArray[1].bullets[1] = 1;

	printf("%i", MyArray[1].bullets[1]);
	printf("%s", "\n");
	system("Pause");

    return 0;
}


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

NOTE: The above doesn't use any AppGameKit commands.
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.
Posted: 14th Oct 2011 13:54
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.

ince 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.
Posted: 14th Oct 2011 14:44
What about:
+ Code Snippet
type weaponType
    ammo as integer
endtype
dim weapon[5,500] as weapon


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...
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
Posted: 14th Oct 2011 23:46
@ Baxslash: That's a good idea except what if you wanted two or more arrays within your type?

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.
Posted: 15th Oct 2011 1:25
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...
Posted: 15th Oct 2011 1:55
Not sure what you mean Hodgey?

Something like this
+ Code Snippet
Type mytype
    Dim Array1[5] as integer
    Dim Array2[10] as float
    Dim Array3[3] as string
Endtype

// then use like this
Dim vars1[100] as mytype
Dim vars2[20] as mytype


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?
Posted: 15th Oct 2011 6: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
Posted: 16th Oct 2011 5:28
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.
Posted: 18th Oct 2011 2: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.
Posted: 18th Oct 2011 6:48
Thanks Lee, I guess if you wanted to use pointers then you'd probably use Tier 2 anyway.
Posted: 21st Oct 2011 4: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.
Posted: 21st Oct 2011 6:15
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.

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:
+ Code Snippet
TYPE weapon
    dim bullets[50]
ENDTYPE

dim guns[10] as weapon

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:
+ Code Snippet
dim bullets[10][50]

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:
+ Code Snippet
type weapon
    pRef as integer
endtype

// create array of guns where each gun will need an array of bullets
dim guns[10] as weapon 
dim bullets[10][50] as integer // basically bullets[NumOfGuns][NumOfBullets]

// initialise each gun with its own reference number
for n = 0 to 10
    guns[n].pRef = n
next n

// We can now use the bullets array like this
for n = 0 to 50 // ie n = 0 to number of bullets
    for o = 0 to 10 // ie number of guns    
        bullets[guns[o].pRef][n] = SomeRandomValueOrFunction
    next o
next n


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.
Posted: 22nd Oct 2011 2:18
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.