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 DBPro Corner / A Tutorial on Arrays

Author
Message
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 12th Nov 2006 16:43 Edited at: 12th Nov 2006 16:47
@Dark Donkey: You're welcome Just read over the beginning a few times and you should get it.

@indi: Thank you

Tutorials:
Array
Functions
iGd
18
Years of Service
User Offline
Joined: 5th Dec 2005
Location:
Posted: 14th Nov 2006 05:36
Wow, Thank you SO much.
I feel 99% more confident in arrays now!
1% + 99% = 100%

Thanks again,
-iGD

-----------------------------------------------------------------

----------------------- Coming 2008 ------------------------
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 15th Nov 2006 02:31
@iGd: I'm glad this tutorial has helped you out!

P.S. If you guys need any more examples then I'll do my best to supply them

Tutorials:
Array
Functions
Inverted
17
Years of Service
User Offline
Joined: 19th Nov 2006
Location: Oregon
Posted: 20th Nov 2006 21:11
Thanks for this tutorial!

Opposites are different, not wrong
David Gervais
Retired Moderator
18
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 11th Dec 2006 17:14
ok, I guess this is the right place to ask,..

Can I DIM arrays within a function and have the array accessible outside the function?

I'm thinking of making functions to initialize a game grid array, but the game grid can be different sizes. 9x9, 11x11, 13x13 etc. My initial thought was to just make the array large enough to hold the largest grid and then only use what is needed.

anyways, any comments are welcome.

Cheers!
Cave Man
17
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 11th Dec 2006 22:08
Quote: "Can I DIM arrays within a function and have the array accessible outside the function?"


Yes.

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th Dec 2006 01:38
But you shouldn't be able to!

Arrays declared inside a function should be local. An example of DB strangeness that can be quite useful though...

DBP is quite happy for you to do it but in DBC it's slightly different in that you have to DIM the array outside the function as well or the program won't run.

However it's a useful way to get really 'global' variables in DBC.

TDK_Man

David Gervais
Retired Moderator
18
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 12th Dec 2006 11:20
Thanks, and yes the reason I asked is because I seem to remember something about 'local' variables vs 'global' in DBP and could not find the old post.

Thanks again, now to do some tests.

Cheers!
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 13th Dec 2006 03:11
@Inverted: Thanks! Sorry for the late response, usually my threads turn light blue when somebody posts in them.

@David Gervais: I'm glad you got that sorted out

Dared1111
17
Years of Service
User Offline
Joined: 25th Oct 2006
Location:
Posted: 16th Dec 2006 10:46
thanks! now i know how to do savegames, something which has bugged me occasionaly

A game- nvidia cancelled but preserved till ive finished the current

Game progress- 5 percent
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 17th Dec 2006 19:42
no prob

Inverted
17
Years of Service
User Offline
Joined: 19th Nov 2006
Location: Oregon
Posted: 17th Dec 2006 21:05
Great tutorial (once again)
Anyways, you should do one on AI!

-inverted

Opposites are different, not wrong
Kieran
17
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 27th Dec 2006 12:47
its good but how would you get it to load 3 different cabinets into a variable? for example

Dim Hat(3)
Hat(1) = 1
Hat(2) = 2
Hat(3) = 3

now I want to use all three at one like

if object collision(1,Hat(1-3))
text 1,2,"Thanks for crashing..."
endif

so it would have if object 1 collided with objects 1, 2 and 3
SimSmall
19
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 27th Dec 2006 13:52
Quote: "if object collision(1,Hat(1-3))"


what are you trying to do with this?

Because, without even compiling the code, I can see that's going to crash Because Hat(-2) doesn't exist. Array indices are numbered from 0 to the number supplied with the dim statement, and that number must be a positive integer... I think what you're trying to do is:



note that it's not x = 1 to 3 since there's little point to see if object 1 is colliding with object 1, 1 being the contents of Hat(1)
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 27th Dec 2006 16:51
I think what you are after is:



SimSmall is correct - you don't supply Object Collision with a range of object numbers, you use 0 as in the code above, then use a loop to check to see if numbers in the range you are testing for are returned.

TDK_Man

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 27th Dec 2006 19:11
Wow a post! I always get here after the problem has been solved Anyway, SimSmall and TDK are right. You can't write Hat(1-3), but you can use the FOR/NEXT command to cycle a variable through a range of numbers. Try this to see what I mean:



Kieran
17
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 28th Dec 2006 03:06
yeah i tried that before it was posted but what happened was

it killed my FPS



ok i executed it it showed 66 FPS which is good
after the for next loop it was 25 FPS so its not a good way to go
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 28th Dec 2006 03:48
Hmmm... Well, that may be the only way. Oh, and I am using a FOR/NEXT on 200 objects in a loop and nothing is happening. Are you sure it wasn't the huge amount of (possibly high-poly) objects that was slowing you down?

z3r0mind
17
Years of Service
User Offline
Joined: 11th Aug 2006
Location: Behind you...
Posted: 26th Jan 2007 05:04
wow nice job with the array tutorial. You do a better job of explaining arrays than the beginner's darbasic guide. I never knew about the custom extensions.
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 1st Mar 2007 23:13
Thanks for the complement! (SORRY FOR RESPONDING SO LATE. The forum (again) didn't tell me you responded)

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 20th Apr 2007 18:48
Sixty Squares:

I've now got the new TGPF forum software up and running and it's now open for anyone to join.

There's a tutorial board in place, with sections for both DBC and DBPro tutorials.

I'd like to have this tutorial on there too, so would you be willing to add it please?

TDK_Man

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 20th Apr 2007 22:52 Edited at: 20th Apr 2007 22:58
Sure thing TDK, thanks for including me

EDIT: Okay I've registered to your forum but it's not letting me post at the moment. I have visited the varification link so I'll have to wait I guess...

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 21st Apr 2007 01:02 Edited at: 21st Apr 2007 01:22
Strange - I'll check for you....

[Edit] Just created a non-mod account and it works fine for posting new topics.

Note: You post your tutorial on the Tutorials root board - the three sub boards are read-only. When user's tutorials are approved (like yours already is), it will be moved into the relevant sub-board by admin.

TDK_Man

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 21st Apr 2007 13:48
Oh okay thanks TDK. I was trying to post in the child board. Is it possible to reply to child board posts?

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 21st Apr 2007 19:15
Not at the moment. Eventually I'm hoping it will be possible to reply to an existing thread but not create a new one.

That way we can ensure that only tutorials we approve appear on the child boards and those created by users and awaiting approval are placed on the Tutorials parent board.

TDK_Man

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 22nd Apr 2007 06:23
Okay then

vorconan
17
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Wales
Posted: 22nd Jun 2007 00:13
I've didn't see this before, but it's very very useful. I hope no one minds me bumping this to make a comment, if so sorry.

I've changed the code of someone's on a previous thread so it now makes a 3d maze if anyone is interested. The camera moves a bit fast at the moment.

Xsnip3rX
17
Years of Service
User Offline
Joined: 20th Feb 2007
Location: Washington State
Posted: 22nd Jun 2007 03:26
Indi Reffered me to this thread, like, a week ago when i was starting on arrays... so it tought me well, ty Sixty for a great tutorial.

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 24th Jun 2007 15:59 Edited at: 13th Jul 2007 03:34
Thanks for your comments! I'm happy this tutorial helped you get moving with arrays

EDIT: Oh, and nice maze

Cygnus
16
Years of Service
User Offline
Joined: 11th Aug 2007
Location:
Posted: 11th Aug 2007 20:19
My string arrays can be saved as .txt files and read with a text editor. However, when I save an integer array, the .txt result is incoherent. It is only a bunch of symbols. I am concerned that this will affect calculations when comparing number to an index in the array. Any sugguestions?
Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 25th Sep 2007 05:27
How do you use blank arrays?

Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 26th Sep 2007 01:42
Dont worry, ive taught myself how to use one.
What i mean is like


Its really useful for bullets ect.

Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 26th Sep 2007 13:19
array(0) works fine for me :/

Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 26th Sep 2007 13:31
Oh ok. thanks

HeavyAmp
17
Years of Service
User Offline
Joined: 25th Oct 2006
Location: Castle in the Sky!
Posted: 28th Sep 2007 03:09
One thing that I had trouble on. If You use Dim Myarray (0) then use empty array Myarray(0) command it will give you an array size that is Myarray (-1) so everytime you do empty array Myarray(0) you also need to make sure you do Array Insert at Bottom Myarray(0) after.

Better to be dead, than to live your life afraid.
Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 28th Sep 2007 11:09
Quote: "Those are called lists, or dynamic arrays in general. You should dim it as array(-1) or array(), otherwise the array is not empty from the outset. Arrays in DBPro are zero-based, so dim array(0) will create an array with one item at index 0."


one thing, if array(0) is registered as having one index, why does this

return a zero?

Aralox
17
Years of Service
User Offline
Joined: 16th Jan 2007
Location: Melbourne
Posted: 28th Sep 2007 12:39
Oh ok - that helps me more anyway

aluseus GOD
17
Years of Service
User Offline
Joined: 19th Mar 2007
Location: I\'m here. Now I\'m there. I keep moving
Posted: 30th Sep 2007 04:07
Whoa! You can save and load arrays?
But someone else beat me to showing me arrays with drawers and cabinets.

Can you save multiple arrays to the same files?

Your signature has been deleted by a moderator because this joke is getting old.
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 2nd Oct 2007 03:04 Edited at: 2nd Oct 2007 03:05
Quote: "Can you save multiple arrays to the same files?"


I don't believe saving multiple arrays to one file is possible with the SAVE ARRAY command, but it could be done with the FILE commands (OPEN TO WRITE, WRITE STRING/WORD/FLOAT etc...).

But you can save multiple arrays to multiple files with the same file extension using the SAVE ARRAY command.

Login to post a reply

Server time is: 2024-04-18 22:23:46
Your offset time is: 2024-04-18 22:23:46