• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

saving a method?

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've learned that through object serialization you can save an object.... how is there a way of saving methods?

because I'm making a game right now and it uses a kinda of script that follows a counter and does actions. say...



and like that, it's a script of what to do when it reached different counters. And now I'm trying to find a way to save this "script", which is actually a method. So the game could get that "script", call the object's scriptCall() method and it will act like a script to make it do stuff...

sry if this isn't the right place to post this, I just didn't think that this topic would fit into the game development section since it doesn't relate that much to gaming...

P.S. I've been thinking that maybe I can find a way to parse instructions like that? but it would be too much of a hassle...
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, Dan!

Let's slide this over to the Java in General forum, where I think you'll get more feedbacks!
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should never need to save a method. your work can be done with saving the object.
move the local variables in your method to instance variables. after that you wont need to save a method
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Short answer is No. You cannot save a method.

Long answer: From what I understood of your problem, what you really want to save is the counter value. Your method implementation does not change. What changes is which implementation to invoke based on the counter count.
Easiest way to save the counter value would be in a properties file.

Does this answer your question or did I misunderstand your problem?
 
Daniel Gen Li
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the answer guys.

I can see some misunderstandings to how it works and why I need to save a "method", let me explain the real story behind all this.

I'm making to damaku game, which basically means a curtain of bullets.

An enemy, for example, has it's own behaviors for shooting and moving, etc, which is done by a method that acts depending on the current counter. for example, if the counter is 10, then fire 260 bullets in all directions. There are a lot of of these conditions, and they come together to form a method that acts as a script for how the enemy should act. So If I save the method, it equals saving the script.

I could just implements a different script-call method for each type of enemy, but there are probably over 60 types of enemy each with different types of movement. I would have to define 60 classes just to have 60 enemies that do different things.

and since saving a method isn't really possible....

i've thought about making a parser, that takes in instructions from a .txt file, and then executed the instructions. But bullets don't just move in a straight like with a constant speed. They can speed up, turn, move in a function, home, or even make more bullets... That makes the parser sound a lot harder to do. And I want this to be a game where players can make their own bosses with cool bullet patterns that they define. 3000 bullets in a circle is easy with a for-loop, but how would I put that for-looping command into a parser and then actually execute it?

I've attached a sample bullet attack, involving hundreds of bullets being fired within seconds. How would I make a parser for a attack such as that

P.S. where's the Java in General forum?

 
Daniel Gen Li
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
btw how can I show the program if i'm not allowed to attach .jar files or .rar or .zip files???
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic