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 / 3-dimensional dynamic non-square array -- how?!

Author
Message
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 15th Sep 2013 17:26 Edited at: 15th Sep 2013 17:41
Hi, fellows!

I am writing trigger script. Trying to write. The plot:
There are ? rooms, each room has ? triggers, each trigger has ? actions to do.

DIM (x,y,z) is broken, square-type only and not working with array commands, so it goes in trash can.

I am planning to have 3 dynamic: room(), trigger(), action()

Notice: non-square


How to find out all actions of trigger #5 in room #9? Plus, how to add/remove actions/triggers/rooms?

Any ideas are avidly appreciated!

mr_d
DBPro Tool Maker
19
Years of Service
User Offline
Joined: 26th Mar 2007
Location: Somewhere In Australia
Posted: 15th Sep 2013 18:45
Hi mr Handy, you didn't say if this was a client only program or a client server one. If it's the later, then the easiest method to do what you what efficiently is to use a database to store all your room, trigger and action data with each one being a separate field of a table. It would look similar to what you have given already, except without the words trigger and action(s) in the data.
You would have simple PHP scripts that would run SQL queries against your database to get the wanted results, running different SQL statements depending on how many parameters your were passing.
If it is a client only program, then you could do something similar using either a sqlite database, or using ODBC or maybe MS ADO on a MS Access Database.
Anyway, the above are the ideas I had for your stated requirements - hope they help, or at least give you some food for thought.
I suppose I should say that you can achieve what you want with 3 separate single dimension arrays and a fair bit more of code to bring back the results you want. Personally, this would be my second choice after using some sort of database. Cheers.

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 15th Sep 2013 19:36
Hi mr d! It is not related to multiplayer or online play. It are rooms in the house, and when you entering them triggers are playing their actions. And they are to be dynamic because I am planning to make an editor for the house, so I can add/remove anything in it in real time. I am not good at DBP, so SQL or Access is a something beyond my mind, plus I believe they would not be so efficient as I need to check database every cycle (60 times per second).

Quote: "I suppose I should say that you can achieve what you want with 3 separate single dimension arrays and a fair bit more of code to bring back the results you want."

Yeas, the main pain is to think out array management system.

A thought:
room() are rooms. Every room contain pointer of first trigger number and how many of them.
trigger() are triggers. Every trigger contain pointer of first action and how many of them.

But then I need to sort them every time I change something, and refresh all pointers...

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 15th Sep 2013 19:51 Edited at: 15th Sep 2013 19:55
Sounds like something I do every day. Here are two that I use in most situations.

Method 1: Link List:


Each element stores its parent ID, and each parent stores its first child; and each child stores its next sibling.

Room(1).FirstTrigger = 1
Trigger(1).Room = 1
Trigger(1).NextTrigger = 2
Trigger(2).PreviousTrigger = 1
Trigger(2).Room = 1
Action(100).Trigger = 2
Trigger(2).FirstAction = 100

And so on. Use functions to make shortcuts.

Method 2: Matrix1 Raw Memory

Yeah I know it seems a bit low-level, but it is fast and I use functions to make it easy to use. This is the method I use 90% of the time.

List = Trigger(1).List = Memory Address (They are the same)

FirstAction = ListItem(List,1) = Peek Integer( List )
ThirdAction = ListItem(List,3) = Peek Integer( List + (3 * 4) )

The parent relation is stored in the UDT.
Action(FirstAction).Trigger = 1

Again helper functions are created for shortcuts such as:

Adding a new item requires a change of memory address, if you want do not want a static list.


The above is achieved with the following, where tuple is the phrase used instead of list:



Addresses change when the list/tuple is resized. For this reasons, I also store lists in a reference array; so lists can be accessed by reference rather than by value.



OR


Iteration is done using Peek commands or a helper function: GetItem( address, index ) | GetListItem( list, index )

Again this is a simplified example of what I am doing.

mr_d
DBPro Tool Maker
19
Years of Service
User Offline
Joined: 26th Mar 2007
Location: Somewhere In Australia
Posted: 16th Sep 2013 12:49
Quote: "plus I believe they would not be so efficient as I need to check database every cycle (60 times per second)."

I'm not sure exactly what you are trying to do, but I believe that you would perform your test to check if you are in any particular room frequently (this wouldn't need to be done as frequently as 60 times per second - I'd use 2-5 times per second myself), and would need to call the query to check the particulars of the room you're in only when that changes. i.e. when you move from room to room - which should be at most once every few seconds at most for normal travel...
In regards to Database libraries, check out this (by GIDustin based on KISTech's library) or this (by Duffer). The second one has much more functionality and would be the one I'd go for, but the first may be simpler to implement and use (not sure as I haven't used it myself) and may suit your purposes more.

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 17th Sep 2013 02:35
Thanks for the advices, fellows! I will try them all!

Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 20th Sep 2013 10:09
Quote: "Yeah I know it seems a bit low-level, but it is fast and I use functions to make it easy to use. This is the method I use 90% of the time."


This is pretty much the exact method I've been using too. I've basically built "structs" directly into memory with help functions in as close to an OOP style as possible. The speed has been good, the extra flexibility around dynamic arrays/lists is almost required, the ability to manage memory more efficiently is certainly nice to have, and you can save memblocks to a file really easily so for creating a save state, whether this is a saved game or saving your creation in a level editor, its perfect.


Previously TEH_CODERER.

Login to post a reply

Server time is: 2026-07-06 16:49:38
Your offset time is: 2026-07-06 16:49:38