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.

Dark GDK .NET / Question about Objects in DarkGDK.NET

Author
Message
Quentin Collins
16
Years of Service
User Offline
Joined: 26th Apr 2007
Location:
Posted: 17th Sep 2009 00:53
Greetings, all... I just recently got DarkGDK.NET and have been playing around with some of the examples to get familiar with it.
At the moment, I'm using VB 2008 Express.

I've figured out how (on a Windows Form) to create a button which, when pressed, will create a cube & position it at 0,0,0 within the DarkGDK Viewport, and this works just fine. See snippet:

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim testcube As New DarkGDK.Basic3D.Cube(10)
testcube.Position(0, 0, 0)

End Sub

I created a second button on the form which, when pressed, is supposed to delete the cube. This is where I'm having the problem - no matter what I do, I can't seem to get rid of the @#$%^! cube... LOL.

I know it's probably something REALLY obvious that I'm missing, but I simply can't figure it out. The documentation only mentions "Public Sub Delete", but not how to actually implement it.
I'd appreciate any help, and of course, I'll keep plugging away at it myself in the meantime (after all, that's how we learn, right?).

"Cube-lessly Yours", (now how's THAT for optimism? LOL)
-Quentin


When this baby hits 88mph, you're gonna see some serious sh..!
APEXnow
Retired Moderator
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 17th Sep 2009 02:01
Quentin,

To delete the cube, just use the following code:

testcube.Delete()
testcube = Nothing

This will remove the 3D cube from memory and will free up the object reference held in testcube.

Paul.

Quentin Collins
16
Years of Service
User Offline
Joined: 26th Apr 2007
Location:
Posted: 17th Sep 2009 02:43
Paul, thanks for the fast reply!

I tried this, but it only seems to work if I put it into the same sub as the one I created the cube in (ie, Button #1). The result is that it creates & then immediately deletes the cube (which is to be expected, but not what I'm looking for).

The problem I'm having is that the code for Button #2 (the one that should delete the cube) is a separate sub, and even though it is Public Shared, it keeps saying "testcube" is undeclared when I put in the code "testcube.Delete()", and it does nothing.

When this baby hits 88mph, you're gonna see some serious sh..!
Quentin Collins
16
Years of Service
User Offline
Joined: 26th Apr 2007
Location:
Posted: 17th Sep 2009 08:14
Ok... this is driving me crazy. Granted, I haven't worked that much with any of the .NET languages, but I didn't think that it would be so difficult to deal with what should be simple variables.

In DBPro, to create & manipulate a simple cube, here's all you need : "make object cube, object_number, object_size". From this point on, you can do pretty much anything you want with the cube by simply referencing it's object_number in the commands you're using. And you can even use "delete object object_number", no problem!

In DarkGDK.NET, while you can still create a cube:
"Dim testCube As New DarkGDK.Basic3D.Cube(20)", and maybe even position it "testCube.position(x,y,z)" - as long as you do it from within the same sub in which the cube was created -
... how on earth do you determine which object number it is, or assign it an object number so you can actually do something with that specific cube, either in the same or in other subroutines, to say nothing of how to delete (if necessary) that specific cube?

I realize I'm new to the whole OOP thing, but for me this is akin to having to learn 10th Level Grand-Master Japanese Origami to create a paper bag for a sandwich lunch... LOL!

Ok... it's now been 4+hours in one stretch with no caffeine or nicotine (but numerous head-impressions on my desk, making a new shiny spot dead center below the keyboard)... I'm gonna take a brief break while anxiously awaiting any enlightenment that anyone may kindly throw my way...

Thanks again, most especially for your patience with a self-proclaimed dolt,

- Quentin

When this baby hits 88mph, you're gonna see some serious sh..!
veltro
User Banned
Posted: 17th Sep 2009 10:25 Edited at: 17th Sep 2009 10:26
VB is really different from DBPro

When you declare the testCube within a sub the variable is local to the sub, i.e its visibility scope is restricted to the sub

If you need the variable to be visible in outer scope, declare it outside the sub, in then form/module declaration section (at the beginning of code just after the form/module keyword).

You can specify the variable visibility is restricted to form module with Private keyword: this way every piece of code inside the form module will have access to the variable.

You can specify the variable visibility is allowed outside form module with Public keyword: this way every piece of code inside the form module will have access to the variable and every piece of code in other forms/modules will have access to the variable too.

To determine the object number use testCube.id (if I remeber well)
but it's always better to use the obejct reference (testCube)
Quentin Collins
16
Years of Service
User Offline
Joined: 26th Apr 2007
Location:
Posted: 18th Sep 2009 08:24
Veltro: I understand what you're saying. Sadly, I can't seem to get this to work, no matter what I try. I'm attaching 3 screenshots so you can see EXACTLY what I'm doing & talking about.
Pic1 shows the Windows Form, with the DarkGDK.NET viewport in the middle, with 2 buttons on the form below it (one to create a cube, the other to delete the cube).

Pic2 shows the form's code, including that of the 2 buttons.
Pic3 shows the code that the buttons are calling, and it is commented with the problem I'm having.

I didn't include the Module1.vb code because it is working fine.
I hijacked the sample program for the spinning torus, remmed-out the code for the torus itself, and it does create & show a cube when I hit the Make Cube button. It's just that there seems to be
no way to code the Delete Cube button in such a way that it will acutally work.

If ANYONE can help me by maybe pointing out the flaw in my code (in whichever form, module, etc it may be), I would DEEPLY appreciate it.

Thanks all,

- Quentin

When this baby hits 88mph, you're gonna see some serious sh..!

Attachments

Login to view attachments
Quentin Collins
16
Years of Service
User Offline
Joined: 26th Apr 2007
Location:
Posted: 18th Sep 2009 08:25
Sorry... here's pic2

When this baby hits 88mph, you're gonna see some serious sh..!

Attachments

Login to view attachments
Quentin Collins
16
Years of Service
User Offline
Joined: 26th Apr 2007
Location:
Posted: 18th Sep 2009 08:26
... and finally, Pic 3:

(Sorry to all, I was a bit too dumb to figure out how to post multiple pics in one post)...

When this baby hits 88mph, you're gonna see some serious sh..!

Attachments

Login to view attachments
veltro
User Banned
Posted: 18th Sep 2009 10:32
The problem is that you declare

dim testcube ...

inside the If statement. You must place it before

This way compile is ok, but execution NOT

You had to remember that when you declare a variable inside a sub or function its scope is local to the sub and its value is discarded at the end of the sub/function.

Plus you are using two difference istances of the class ObjectHandle so they will never share the same variable/value

You need to change the ObjetHandle Class inserting

Private Shared testcube As DarkGDK.Basic3D.Cube

before sub makecube
(the keyword Shared ensure that all instances of objecthandle will use the same variable)


Then change makecube sub

if choice = 1 then
testcube = DarkGDK.Basic3D.Cube(100)
end if

if choice = 2 then
testcube.delete
testcube = nothing
end if


Hope this help
Quentin Collins
16
Years of Service
User Offline
Joined: 26th Apr 2007
Location:
Posted: 18th Sep 2009 12:05
Veltro, my friend... you are a GENIUS! I have fixed my code as you suggested, and now it is working PERFECTLY! My next task will be to attempt coding an array into which to store multiple object ID's so that they can be independently manipulated... and who knows? I might even be able to write the great Object Designer / Level Editor I've always dreamed of, someday... LOL!

Wow... what an adventure! You're right, though... VB is a very long way from the old-style BASIC languages I'm used to... but I promise I'll keep learning. Considering this is only my first week working with VB (and DarkGDK.NET, for that matter!), I think I am off to a good start.

Thank you VERY MUCH for all of your help! This is one of the reasons I've become such a fan of the Game Creators... great products, and an even greater community!

Your Friend,
-Quentin

When this baby hits 88mph, you're gonna see some serious sh..!

Login to post a reply

Server time is: 2024-04-19 19:52:00
Your offset time is: 2024-04-19 19:52:00