Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Java

Reply
 
LinkBack Thread Tools Display Modes
Old 06-27-2009, 10:45 PM   #1 (permalink)
themanofum
Recruit
 
Join Date: Jun 2009
Posts: 9
themanofum is on a distinguished road
A little problem triggering things...

(Synopsis below)

I've been working on a RTS (real time strategy) video game for quite a while now, and have decided over time to implement a system of "triggers". Those with previous knowledge of such games would know that triggers are system used in games to tell things to perform actions when a certain event occurs in the game world. However, I'm rather clueless on where to begin with the implementation of this trigger system.

The way the trigger would work would be simple. One or a series of variables are tripped by other things in the game world (time passing, objects moving to a certain place, etc.), and the trigger then tells several events to occur as a result of this. (money being given or units being destroyed).

The problem I'm encountering in the early stages of implementation of this system is the dynamic nature of the variables that can activate any given trigger. One type of trigger may say "when a tank goes to location A and the player has 5000 dollars, destroy a tank in location B" while another may say "when 500 frames have passed, give the player 2000 dollars and blow up his defenses". So no one constructor would work to make a trigger which could be used with all the necessary properties.

Synopsis :
What I need is something that can create a trigger (or condition-like) object that can have changing amounts of multiple variables of different classes within a single constructor. Any ideas on how to do something like this, or the counsel of anybody who has stumbled on this problem before would be greatly appreciated.
themanofum is offline   Reply With Quote
Old 06-28-2009, 01:05 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,230
Belisarius is on a distinguished road
Well, you could keep a central registry of all the game-objects in a singleton, then the triggers would be able to look through all the elements it needs to in order to see if the condition has been satisfied.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 06-28-2009, 01:43 PM   #3 (permalink)
themanofum
Recruit
 
Join Date: Jun 2009
Posts: 9
themanofum is on a distinguished road
The problem isn't keeping track of the objects, it's that the type of constructor needed varies so greatly from trigger type to trigger type

for example, one type of trigger may need an int, an int, and a double to operate whereas another may need a String, an int, a double and a char to operate, and there are too many of these guys to just mass-produce constructors to all of them.

the type of thing I'm looking for is a way to have a constructor be able to take any combination of data types or objects and use them appropriately based on the type of trigger it is

Edit : problem solved! Strings can be used to hold all the necessary information! thanks for trying belisarius
themanofum is offline   Reply With Quote
Old 06-29-2009, 09:21 PM   #4 (permalink)
Deliverance
C++ Beginner
 
Join Date: Jul 2005
Location: Ottawa
Posts: 87
Deliverance is on a distinguished road
It seems to me that your trigger system objects only share one thing in common:

Trigger interface.

In this case, I'd recommend a factory class that can construct a type of trigger based on your parameter criteria. Going further on this, it seems every trigger needs to execute() as well.

You'll find that String manipulation is very expensive in processing depending on your criteria (remember that they are immutable).
Deliverance is offline   Reply With Quote
Old 06-30-2009, 12:57 PM   #5 (permalink)
themanofum
Recruit
 
Join Date: Jun 2009
Posts: 9
themanofum is on a distinguished road
well, the trigger would only be parsed once, and there would only be a few hundred at the absolute maximum, so really, the high costs of using strings are bearable
themanofum is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving things around sde Lounge 0 09-01-2004 02:16 PM
jsp page triggering twice sde Java 1 09-01-2004 09:32 AM
Dynamic Dropdown & Triggering Results jjfletch PHP 0 08-20-2004 06:27 PM
Things to do... (another funny!) MiLady Mirlyn Lounge 0 05-12-2002 07:14 PM


All times are GMT -8. The time now is 04:43 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting