Jump to content
  • Advertisement
Sign in to follow this  
Endar

Hmmm.....design problem

This topic is 5052 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

I'm working on a little scripting language. So, You have an instruction like "7 + 4", right, and then you have an assignment instruction: "variable = 7 + 4;". I am having a problem. I have a basic instruction class. There is a Variable object (class with float, int, string, so can hold either value) that is used as the return value for that instruction: eg. a multiplication or addition instruction. Each instruction object has a function 'execute' (defined as pure virtual in the parent class). For the assignment instruction, it has an Instruction* data member that points to an Instruction object that it calls execute on and then grabs the return value and then assigns it. So, the problem now is, I have a vector of Instruction objects, and this object that the return value is grabbed from comes OFF THE ASSIGNMENT OBJECT instead of being in the vector that all the other instructions are in. I saw that this really wasn't the best way because that could become really confusing. I also thought of splitting it up into 2 instructions. So vector would be the addition instruction and that would keep its value, and then the value would be passed to the assignment instruction (vector[i+1]), and then it would do the assignment. Is this a better way? Can someone think of a better way than this?

Share this post


Link to post
Share on other sites
Advertisement
I think for arithmetic you would find a stack more advantageous and less confusing.

I suggest all arithmetic operations should be done on the stack and the assignment pops the top of the stack.

Does this help?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!