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 / Quick. UDT. Question

Author
Message
Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 29th Oct 2012 12:25 Edited at: 29th Oct 2012 12:26
Hey all,

Just curious if I've missed something here...



Is there a way to do the following, keeping the above in mind?

MyArray(0).Primary = 1

Because I've declared Primary as Type_Second, I have to follow through with this...

MyArray(0).Primary.Secondary = 1

And I can't assign a value to just MyArray(0).Primary.

Is this one of those DBPro limitations? Or do other languages have this problem too... or am I just missing something obvious.




Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 29th Oct 2012 12:45
Dunno the correct technical lingo but anyway. From my understanding when you declare a member AS a type, that member inherits the attributes of said type - including being a type if the type is a type. So you are saying in your code that "primary" inherits from "type_second". Therefore "primary" becomes a type....something like that... But essentially your code was trying to do was the same as this:


RP Functions Library v1.0

Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 29th Oct 2012 16:03
Using a temp variable to dump in to the array




[img][/img]


WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.
Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 29th Oct 2012 23:16 Edited at: 29th Oct 2012 23:16
Well, I should have posted my current work around, which is this;


MyArray(0).Primary.Value = 1

I was just hoping that there was some way to assign a value directly to .Primary, rather than using .Primary.Value as it's a pain always having to write .Value.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 29th Oct 2012 23:36 Edited at: 29th Oct 2012 23:37
What if your UDT had more than 1 variable in it?


If you think about what you're trying to do:
MyArray(0).Primary = 1

How would it know what variable to assign "1" to?

"You're not going crazy. You're going sane in a crazy world!" ~Tick
Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 29th Oct 2012 23:54 Edited at: 29th Oct 2012 23:56
Yah, exactly Phaelax, that's my work around, add ".Value" to the secondary type.

Obviously my real world example isn't as straight forward, I have roughly a 5 length UDT for the mouse, example;

Print Mouse(1).Single.Press.Selection.Current

`Mouse(1) - Left Mouse button, (2) Right Mouse button

`.Single, single click, this is where I need a .Value. It'd be awesome if I could write;

Mouse(1).Single.Press

to trigger upon a single mouse button depression, but instead I now write

Mouse(1).Single.Press.Value

Because I have a further chain of types which follow after Press, such as;

Print Mouse(1).Single.Press.Object.Selection.Current

Which returns the ID of the object that's been single pressed.

The reason I'm exploring UDTs in UDTs in UDTs, is that I'm not too sure which way I should code my mouse... either way works, but I'm just trying to do it "right"...

Here's my first system, worked OK, but got a dash confusing.


So I started venturing into UDT.UDT.UDT, as per below.



Any suggestions? What's your favorite method of storing mouse/keyboard data?

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 30th Oct 2012 12:29
Why use an array? You only have 1 mouse. And I'm not sure what key state "hover" would mean in terms of a key.

You've inspired me to write the following snippet:
http://forum.thegamecreators.com/?m=forum_view&t=201158&b=6&p=0

"You're not going crazy. You're going sane in a crazy world!" ~Tick
Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 30th Oct 2012 12:36
Phaelax, whilst writing my RTS I found that I needed to know what object the mouse was hovering over. So I decided to store the ID of the object within the mouse array, cause, well, it kinda made sense. Mouse cursor is hovering over a tank... Mouse(0).Cursor.Object.Hover = Tank ID, etc.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Oct 2012 16:10
You posted this earlier: Primary.Secondary = 1

That doesn't even make sense and it would make more sense to structure it like this:


I really don't understand the logic in this. Using array's for the left and right mouse button, you've just wasted a ton of variables that are not doing anything because the left, right and any other button will all share the same information. Saying that, each index in the array declares something like 60 variables. That's 60x5 variables doing nothing half the time sitting in memory. I really would suggest restructuring this. Everything you only need one of should be in the root type, like position for instance. Though if your going to use arrays then I would suggest storing position or things like that in something else so you don't end up with the multiples of the same variable.
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 30th Oct 2012 21:10
Two cents worth...



Enemy(x).mouseOver determines whether bothering to check Enemy(x).mouseClick and obviously .mouseClick would be the button clicked on it. I used a similare system for I GUI Windowing system I started working on yonks ago and I figure it would translate fairly okay for what you need.
The current object could be stored as something simple like curObject or whatever.
Well, maybe I'm missing what you're wanting to do. If not, hope this helps.

RP Functions Library v1.0

Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 10th Nov 2012 02:36
Ever since building up my UDTs, things are working out a whole lot easier for troubleshooting. I love it how a simple typo will fail to compile now, instead of sneaking in and causing havoc with the engine!

What work around do you guys use due to the lack of nested arrays? At the moment, I'm doing this;

Type_Pos
X as Integer
Y as Integer
Z as Integer
EndType

Type Type_Example
Pos as Type_Pos
Pos_Cache_1 as Type_Pos
Pos_Cache_2 as Type_Pos
Pos_Cache_3 as Type_Pos
EndType

as opposed to;

Type Type_Example
Dim Pos(3) as Type_Pos
EndType

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Nov 2012 03:33 Edited at: 10th Nov 2012 03:34
If you want to use a fixed array size then it's easy to keep track of elements.

Let's take this example, which obviously won't work (but we all wish it did):



Since 'q' has a fixed size of 10, we can do this instead:


"You're not going crazy. You're going sane in a crazy world!" ~Tick
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 10th Nov 2012 16:38
Quote: "Print Mouse(1).Single.Press.Object.Selection.Current"


I get what you did, it's pretty clear what the values represent. I'd use binary states in place of one variable per state; it takes getting used to, but then you equip yourself with the ability to use 1 byte of data and be able to determine what button was pressed, and what button was released etc. With 64 bit CPUs now, you can store 64 states in a single variable.

Picture this:


You could then use just one variable to store the button state:
ButtonState = ButtonState || Hover `1

You can store more than one event in that variable, up to 32 (bits)
in an integer (or DWord) ButtonState = ButtonState || Hover || Release || Drag || WhatEver `1

And check if something is true using the && ( or and) operator. My binary operation tutorial)

Quote: "
What work around do you guys use due to the lack of nested arrays?
"


It depends; what ever is good for the situation. Sometimes, I store the array in a memblock or membank. I can put however many arrays I want in them.

Sometimes, I store a list of array pointers (Get ArrayPtr function).

You also have Matrix1 freelists; they can be used as arrays in arrays that link to what ever you want.

Most of the time, I try not to need nested arrays in the first place. In other words, use DBPRO arrays for what they are good for; which is not storing hierachies. lol.

No, really; you can nest array elements to other elements, in link list form.

MyChild = Array(1).FirstChild
MyParent = Array(1).Parent
NextSibling = Array(1).NextSibling

While Array(NextSibling).NextSibling > 0
Do Actions
NextSibling = Array(NextSibling).NextSibling
Endwhile


Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 15th Nov 2012 09:31
I love Boolean & operators. You've both reminded me to revisit the efficiency of my mouse code, whilst also confirmed my options regarding the structure of the code.

I'm going to read up on Matrix1 freelists to see if they're worth employing. If anything, re-writing my mouse function over and over is teaching me skills I never had before. It gives me great confidence to tackle the next things in line, specifically queues & and object management.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 15th Nov 2012 10:13
Good, good.

Login to post a reply

Server time is: 2024-11-23 17:44:36
Your offset time is: 2024-11-23 17:44:36