Archived

This topic is now archived and is closed to further replies.

Visual Basic - Creating Objects during runtime

This topic is 5112 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Just looking for documentation on this. I''m working on a quick little game, and i''ve got a class that holds the data for items that appear in the game. No problem. I can create the items with code. What i need is to understand how to do that during run time. Thanks.

Share this post


Link to post
Share on other sites
Maybe I''m misunderstanding, or misrepresenting what I mean, but that''s to create one from code, before runtime.

I need to be able to run the program, then spawn objects based on that class, modify it, delete it, etc.

Thanks!

Share this post


Link to post
Share on other sites
Fair enough.

Let's say I have a class. "Monsters". This class has various properties of it that have no bearing on this exercise. For example, were I making a RPG type of a game, and want to have Monsters spawn in the game, and remove them when they die.

I can easily set up monsters BEFORE the game runs, in code, using :

Set newMonster = New myClass

However, I need to be able to spawn instances of that class *during* runtime, to simulate monsters created on the fly.
This way, once the game is running, i'm not limited to only monsters I created before I compiled, but can dynamically create and track these news instances of the class, modify them, then remove them from the collection when it's all over.

Thanks!

[EDIT]

It appears that I got it. Looks like VB tracks everything for me, so I can do it just fine.. Thanks for the help, all!


[edited by - Mortanis on December 15, 2003 7:17:55 PM]

Share this post


Link to post
Share on other sites
dim monsters as collection
dim monster as Monster

set monsters = new collection
set monster = new Monster
.....

monsters.add monster


monsters(0).Move...

etc..

You can create Monsters in run-time the same way you do in compile time on a trigger/event.

Keep the monster references (object pointers) in a collection where you can re-reference them during your game. Then at the end of the game delete the objects in the collection.

-Viktor

Share this post


Link to post
Share on other sites