At 2/13/15 05:10 PM, liossenel wrote:
I'm trying to create a project based on dating sim's gameplay. the first set of variable contains 4 int, and the second contains 4 boolean. Each int expresses a specific npc's affinity with the player, and each boolean expresses if the player has access or not to each character's specific event.
4 affinity int and 4 spe-event boolean.
The code you had in your first post was actually pretty close to what you want.
As you have to deal with NPCs it makes sense to have them as such in your code and do not deal with individual ints and booleans.
Here's some untested example code to illustrate how an NPC class could look like:
package
{
public class NPC
{
private var _affinity:uint;
private var _specificEventUnlocked:boolean;
public function NPC()
{
_affinity = 0;
_specificEventUnlocked = false;
}
public function get affinity():uint
{
return _affinity;
}
public function set affinity(value:uint):void
{
// limit affinity to the range 0 - 100
_affinity = Math.min(100, Math.max(0, value));
}
public function get specificEventUnlocked():boolean
{
return _specificEventUnlocked;
}
public function set specificEventUnlocked(value:boolean):void
{
_specificEventUnlocked = value;
}
}
}
Each npc should have an affinity and a boolean variable to tell if the special event is unlocked.
Creating a class NPC with both variables covers that nicely.
You use this like so:
var john:NPC = new NPC();
john.affinity = 20;
trace("Is john's special event unlocked? " + john.specificEventUnlocked);
As you can see, the class allows you to bundle the variables together and deal with them in a convenient package (an object).
But you can also add specific behaviour like forcing the provided affinity into a certain range.
If you were using bare variables on the timeline, you'd always have to do these checks whenever you changed the value of the variable.
So far, the variables can be both set and get. This is not very realistic.
You probably want to enable the special event when a certain condition is met automatically. As an example, when a certain threshold affinity is met.
Here's an alternative version of the above NPC class that takes the threshold that unlocks the special event as a parameter:
package
{
public class NPC
{
private var _affinity:uint;
private var _specialEventThreshold:uint;
public function NPC(threshold:uint = 100)
{
_affinity = 0;
_specialEventThreshold:uint = threshold;
}
public function get affinity():uint
{
return _affinity;
}
public function set affinity(value:uint):void
{
// limit affinity to the range 0 - 100
_affinity = Math.min(100, Math.max(0, value));
}
public function get specificEventUnlocked():boolean
{
return _affinity >= _specialEventThreshold;
}
}
}
Notice that there is no boolean variable in this code.
In the code above, the question "is the special event unlocked" is the same as asking "is the affinity greater than the threshold?".
By providing a method (public function get specificEventUnlocked) the class fakes to have a variable that doesn't exist internally.
Other than passing a value as the parameter, it is used in the same way as the other example:
var jane:NPC = new NPC(60);
jane.affinity = 20;
trace("Is jane's special event unlocked? " + jane.specificEventUnlocked);
jane.affinity = 80;
trace("Is jane's special event unlocked now? " + jane.specificEventUnlocked);
As you can see, it takes a bit of code to set a class up, but it can also simplify the rest of your code.
You can work with it as if there's a boolean even though internally, there's no boolean variable.
This is just an example of what you can do. You did not specify what condition should be met to unlock a special event of an npc, so I made this one up.
then, comes the army of button.
I can manage the basic buttons ( go to next/specified frame and play/ stop) with the pre-made code of cs5.
But about buttons saying (if clicked, adds 1 at X's affinity) and/or (if clicked, substracts 1 at x's affinity) I am still experimenting. then, there are buttons with conditions like
-if X's affinity value is equal or superior to Y, go to frame A
-else, if X's value is inferior to Y, go to frame B
I assume that you only want to change the NPC's frame, if this is not the desired behaviour, specify what you want.
This is very similar to what I did above: whenever the affinity is changed, you can evaluate the new value and do things accordingly. (In the above example, I limited the value to be within the range 0 - 100)
Adding the code from the first snippet you posted, you get something like this:
package
{
public class NPC extends MovieClip
{
private var _affinity:uint;
private var _specialEventThreshold:uint;
public function NPC(threshold:uint = 100)
{
_affinity = 0;
_specialEventThreshold:uint = threshold;
}
public function get affinity():uint
{
return _affinity;
}
public function set affinity(value:uint):void
{
// limit affinity to the range 0 - 100
_affinity = Math.min(100, Math.max(0, value));
if (_affinity <= 10)
{
gotoAndPlay("Frame 2");
}
else if (_affinity == 10)
{
gotoAndStop("Frame 3");
}
}
public function get specificEventUnlocked():boolean
{
return _affinity >= _specialEventThreshold;
}
}
}
You have to associate this class as the base class of the library symbols of your NPCs.
The class extends MovieClip and is able to use the methods of this class, in particular: gotoAndStop(), gotoAndPlay()
The code is untested and probably lacks imports, if you receive errors and cannot fix them: post them.