Hey guys I'm creating a finite state machine but everytime I make a function with reference to another class it wont let me is there any way I can use my machine to change states of an object in another class? thanks :)!
5 replies to this topic
#1
Posted 14 December 2011 - 08:17 AM
|
|
|
#2
Posted 14 December 2011 - 09:06 AM
Have you added the reference?
using clause?
Do you have a reference in that class, preferably an interface?
Post some code, not the whole thing, just some headers, etc
using clause?
Do you have a reference in that class, preferably an interface?
Post some code, not the whole thing, just some headers, etc
#3
Posted 14 December 2011 - 10:17 AM
this is my state machine I have other classes that I want to link it too :) basically objects that i want to change states for but im not sure how to do this any help really appreciated thanks :)!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using XNAMachinationisRatio;
namespace FishORama
{
class Fsm : OrangeFishToken
{
public enum State
{
Hungry,
Feeding,
Digesting
}
private State _state; //this is the local variable that represents our state
public Fsm(X2DToken pToken) : base(OrangeFishToken, aquarium)
{
}
void Start ()
{
_state = State.Hungry;
switch (_state)
{
case State.Hungry:
Hunger(); // add function
break;
case State.Feeding:
break;
case State.Digesting:
break;
}
}
}
}
}
#4
Posted 14 December 2011 - 10:54 AM
If you want external classes to be able to change the state of this object, you'll need to write access methods for that functionality, since _state is a private member (and rightly so!)
The most common way I can think of would be to create a public method called "setState" and pass in a FishORama.Fsm.State enum type as a parameter. Inside this method, you simply assign the value of the parameter to your _state private variable.
Edit: And then you simply call setState() from your other class.
The most common way I can think of would be to create a public method called "setState" and pass in a FishORama.Fsm.State enum type as a parameter. Inside this method, you simply assign the value of the parameter to your _state private variable.
Edit: And then you simply call setState() from your other class.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
#5
Posted 14 December 2011 - 10:57 AM
unfortunately, that code fragment didn't help me. Are the other classes in the same project, or in a separate project in the solution?
If classes are not part of the same project, here are the steps that are used to add a reference:
Right click on project -> Add Reference -> select the reference in one of the tabs (if it's another project, select the project tab. If in the GAC, etc., or just lookup the dll)
If classes are not part of the same project, here are the steps that are used to add a reference:
Right click on project -> Add Reference -> select the reference in one of the tabs (if it's another project, select the project tab. If in the GAC, etc., or just lookup the dll)
#6
Posted 14 December 2011 - 11:40 AM
thanks for the help guys :D ill give it a shot :)!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









