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.

DarkBASIC Professional Discussion / examples of lists of userstypes in dbpro?

Author
Message
otakucg
22
Years of Service
User Offline
Joined: 12th Mar 2003
Location:
Posted: 13th Mar 2003 04:21
Heyaz,

Anyone have any examples of lists of usertypes in dbpro?

When I use ARRAY INSERT AT TOP it seems to set ALL of my user defined types to the same value. What I am trying to do is create a dynamic list of objects that shrinks and grows.

Here is a clip the area I am having issues with.



Thats how I create the objects... in the same loop I update the objects and check to see if they are on screen. if they are not I delete them.



Now here is where my issue comes in. In my drawing portion at a certain point I start getting invalid list items or items with no objects in them.



At some point my program exits saying that sprite numbers should be 0 and above. It looks like I am setting it up correctly but its not working for me. Any advice from anyone? Its hard to use the debugger because it doesnt show user defined types like visual c++ does.

Thank You!
otakucg
otakucg
22
Years of Service
User Offline
Joined: 12th Mar 2003
Location:
Posted: 13th Mar 2003 04:24
it clipped my delete code:



swdave
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United States
Posted: 13th Mar 2003 08:29
Hi,

This example might help you.



rem The Dim creates 1 element with index 0
DIM bullets(0) AS bulletType

rem The insert adds element 2 with index 1
ARRAY INSERT AT BOTTOM bullets()

rem This assigns values to element 0
rem because array count is 1 less then the total
bullets(ARRAY COUNT(bullets(0))).posX = player.posX
bullets(ARRAY COUNT(bullets(0))).posY = player.posY
bullets(ARRAY COUNT(bullets(0))).spriteNum = bsprite

Some tips

After dimming an array delete element 0 then it can easily used as a list in a loop.

if array count() = -1 then the array is empty
if array count() = 0 then the array has one element

Use the arrays internal index instead or array count.
array insert at bottom MyAry()
MyAry() = "Hello "

Some people create arrays and don't use element 0 but the list, queue, and stack functions use it.

The array,list,stack,queue all work interchangeably on any array.

I believe the only show stopper bug is inserting in the middle of an array(list).

Hope it helps
Dave...

otakucg
22
Years of Service
User Offline
Joined: 12th Mar 2003
Location:
Posted: 13th Mar 2003 23:46
Heyaz Dave,

Thank you sooo much! I now have a lot better understanding of the setup. I was starting from 1 because all of the other examples when dealing with arrays started at one and ive dealt with different languages that the index start differs. Now I worked with the new setup BUT I am still having the same issue I was. Here is the complete code cleaned up.



This is what happens when you run the code. When you hit the mouse button it creates a list item, translates it in y, checks to see if its gone off screen, deletes the list item if its gone off screen, then displays the item.

Now if you click and let go. It creates bullets and they get deleted all happy like. You can keep on doing so all you want... BUT when it creates and deletes a list item in the same loop (hold down the mouse button until it errors)I am getting invalid numbers for spriteNum. So I can only assume that the rest of the values in my user defined type are also invalid.

Anyone have any input for me por favor?

Thank You again!,
Otakucg

Fluffy Paul
22
Years of Service
User Offline
Joined: 16th Dec 2002
Location: United Kingdom
Posted: 14th Mar 2003 13:26
It's the ARRAY DELETE ELEMENT that's crashing the program.
I altered your program in a number of ways but none of them worked... considering my Final Year Project is a game that does very similar things I thought I could fix it - after all my project works. However, my project does not delete a single array index from the middle of an array, only the ends. My project also keeps track of what array index numbers have been used so I can recycle them quickly without having to resize my arrays (which is expensive in terms of performance). So here's your code done my way!



Because this system uses the position of things in the bullets() array you'll have to keep all the zeros. I've still managed to crash it but it's nothing to do with the index deletion now - probably my dodgy mouse driver! The fairest way to check it is to REM out the "if mouseclick()" and corresponding "endif" but don't REM out the lines in between, that way is makes a new sprite every frame.
Hope that was helpful!

Ending a sentence with a French word is so passé

Login to post a reply

Server time is: 2025-05-19 02:16:46
Your offset time is: 2025-05-19 02:16:46