Interaction instance not requesting state.

Talk nerdy to us here.
Post Reply
User avatar
lyralei
Reactions:
Posts: 13
Joined: January 30th, 2021, 5:36 am

Interaction instance not requesting state.

Post by lyralei » January 30th, 2021, 6:01 am

Hey everyone!

Currently, I'm trying to populate a path with multiple interaction items in the pie menu of my gameObject. Now, what's happening is that once the code goes from 'GetJournal' to 'ReadSimsJournal' to fire that code, everything works except for one particular line in the state machine. The 'GetJournal' calls an instance of the ReadSimsJournal and pushes that to the sim's queue.

So, once it reaches the 'ReadSimsJournal' 's Run() code, everything works, except for anything where the statemachine is calling the sim actor.

GetJournal:

Code: Select all

//Parent interaction that "Gets the journal". This works as expected and the sim gets the interaction
public class GetJournal : Interaction<Sim, LyraleiJournal>
{
public abstract class Definition : InteractionDefinition<Sim, LyraleiJournal, GetJournal>
{
public InteractionDefinition IntDef;
public Definition()
{
}
}
public class DefinitionReadJournal : Definition
{
public string MenuPath;
public string MenuText = string.Empty;
public TypeOfJournalEntry TypeEntry;

public DefinitionReadJournal()
{
}
public DefinitionReadJournal(InteractionDefinition intDef)
{
base.IntDef = intDef;
}
public DefinitionReadJournal(string name, string path, TypeOfJournalEntry entry, InteractionDefinition intDef)
{
MenuText = name;
MenuPath = new string[1]
{
path
};
TypeEntry = entry;
base.IntDef = intDef;
}
public override string GetPath(bool isFemale)
{
return MenuPath;
}
public DefinitionReadJournal nameOfInteraction;
public InteractionObjectPair itemName;
public override void AddInteractions(InteractionObjectPair iop, Sim actor, LyraleiJournal target, List<InteractionObjectPair> results)
{
if (target.SaveJournalEntries.ContainsValue(TypeOfJournalEntry.AbductionExperienceEntry))
{
print(ReadSimsJournal.Singleton.ToString());
DefinitionReadJournal nameOfInteraction = new DefinitionReadJournal("Abduction entries", "Read...", TypeOfJournalEntry.AbductionExperienceEntry, ReadSimsJournal.Singleton);
InteractionObjectPair itemName = new InteractionObjectPair(nameOfInteraction, iop.Target);
results.Add(itemName);
print("Added Abduction to Interaction pair"); }

DefinitionReadJournal nameOfInteraction = new DefinitionReadJournal("Good Relationship entries", "Read...", TypeOfJournalEntry.GoodRelationshipEntry, ReadSimsJournal.Singleton);
InteractionObjectPair itemName = new InteractionObjectPair(nameOfInteraction, iop.Target);
results.Add(itemName);
print("Added Good relationship to Interaction pair");
//results.Add(new InteractionObjectPair(new DefinitionReadJournal("Good Relationship entries", "Read...", TypeOfJournalEntry.GoodRelationshipEntry), iop.Target));
}
}
public override string GetInteractionName(Sim actor, LyraleiJournal target, InteractionObjectPair interaction)
{
return MenuText;
}
public override bool Test(Sim actor, LyraleiJournal target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
if (actor.IsPet || actor.SimDescription.ToddlerOrBelow)
{
return false;
}
if (target.SaveJournalEntries.Count <= 0)
{
return false;
}
return actor.SimDescription.SimDescriptionId != target.mOwnerDescId.SimDescriptionId;
}
}
public static InteractionDefinition SingletonReadJournal = new DefinitionReadJournal();
public override bool Run()
{
if (!base.Target.GetAndPlaceHomework(this, null))
{
CarrySystem.PutInSimInventory(base.Actor);
return false;
}
InteractionInstance interactionInstance;
if ((base.InteractionDefinition as Definition).IntDef == null)
{
interactionInstance = ReadSimsJournal.Singleton.CreateInstance(base.Target, base.Actor, base.mPriority, base.Autonomous, true);
}
else
{
InteractionDefinition intDef = (base.InteractionDefinition as Definition).IntDef;
interactionInstance = intDef.CreateInstance(base.Target, base.Actor, base.Actor.InheritedPriority(), false, true);
}
if (base.Target.Parent != null)
{
ChildUtils.SetPosturePrecondition(interactionInstance, CommodityKind.Sitting, CommodityKind.InFrontOfSurfaceForTarget, CommodityKind.ChairScootedIntoSurface);
}
// Pushing this so we can actually
if (base.Actor.InteractionQueue.PushAsContinuation(interactionInstance, false))
{
base.StandardExit(false, false);
return true;
}
}
ReadSimsJournal:

Code: Select all

public class ReadSimsJournal : Interaction<Sim, LyraleiJournal>
{
public class Definition : InteractionDefinition<Sim, LyraleiJournal, ReadSimsJournal>
{
// Only has a test function here. Nothing else anymore. Used to be identical to the GetJournal's Read definition.
}
public static InteractionDefinition Singleton = new Definition();

public override bool Run()
{
print("Starting");
print("Actor name: " + base.Actor.FirstName); // Returns proper name, so the Actor is definetally working.

base.StandardEntry(true);
print("Entry");
mPosition = base.Target.Position;
if (base.Target.Parent != null)
{
print("Has parent");
}
StateMachineClient stateMachineClient = StateMachineClient.Acquire(base.Actor, "homeworksolo");// Also did base.Actor.ObjectId and base.Actor.Proxy.ObjectId but nothing.
stateMachineClient.SetActor("homework1", base.Target);
stateMachineClient.SetActor("homework2", base.Target);
stateMachineClient.SetActor("x", base.Actor);
stateMachineClient.SetParameter("inInventory", false);
stateMachineClient.SetParameter("startFromInventory", false);
if (base.Target.Parent != null)
{
stateMachineClient.SetParameter("surfaceHeight", SurfaceHeight.Table);
stateMachineClient.SetActor("chair", base.Actor.Posture.Container);
stateMachineClient.SetActor("table", base.Target.Parent);
}
else
{
stateMachineClient.SetParameter("surfaceHeight", SurfaceHeight.Floor);
print("Should be floor in my case"); // This is correct.
}
if (mJournalSurface != null)
{
SurfaceSlot surfaceSlotFromContainedObject = mJournalSurface.Surface.GetSurfaceSlotFromContainedObject(base.Target);
mJournalSlot = surfaceSlotFromContainedObject.ContainmentSlot;
stateMachineClient.AddSynchronousOneShotScriptEventHandler(100u, EventCallbackParentToSurface);
stateMachineClient.AddSynchronousOneShotScriptEventHandler(101u, EventCallbackParentToSurface);
}
else
{
print("Should go here"); // This is true.
stateMachineClient.AddSynchronousOneShotScriptEventHandler(101u, EventCallbackParentToSurface);
}
base.BeginCommodityUpdates();
base.Actor.SkillManager.StartGainAndAddSkillIfNeeded(SkillNames.Writing, 2f);
base.Target.CopyingSim = base.Actor;
base.Actor.LookAtManager.DisableLookAts();
Print("Begin DoHomeworkLoop");

foreach (KeyValuePair<string, ObjectGuid> mActorName in stateMachineClient.mActorNames)
{
print("Actor: " + mActorName.Key.ToString()); // Found actor x
print("Actor OBJ Guid: " + mActorName.Value.ToString()); // Found actor's OBJ guid and it's the correct one too. Double checked this :p
}

// This is where it goes wrong. Sim is not animating despite the game thinking they are, so I assume it just can't seem to find the actor. The state does exist and works fine in other interactions, so that's not the problem.
// Using stateMachineClient.EnterState() will 'animate' (Which is just them standing, doing nothing) the sim, stateMachineClient.RequestState will cancel the animation all together.
stateMachineClient.RequestState("x", "DoHomeworkLoop");

print("Entering to do Homework loop");
bool flag = DoLoop(ExitReason.Default, LoopDel, stateMachineClient);
base.Actor.LookAtManager.EnableLookAts();
base.EndCommodityUpdates(flag);
stateMachineClient.SetParameter("inInventory", true);
base.Actor.SkillManager.StopSkillGain(SkillNames.Writing);

// Also not animating.
stateMachineClient.RequestState("x", "Exit");
base.Actor.Inventory.TryToAdd(base.Target);
base.Target.UnParent();
base.Target.RemoveFromUseList(base.Actor);
base.StandardExit(true);
return true;
}
}
(Sorry for the horrible indentation, the copy/pasting is causing most of that)

The Jazz script seems to work with the targets. It also finds the Actors as well as the sim linked to it with the correct ObjectGuid and stuff.

Now, the problem is, if I use RequestState() the sim will just stand there and do nothing. Now if I used base.AnimateSim() it will give me a null reference error.

I know this jazz script works since this GameObject has the same animation happening in other interactions that do work and can find the sim actor. Just not this interaction :p And I honestly suspect it has something to do with the instantiating of the interaction with another 'main' interaction.

User avatar
Chain_Reaction
Site Admin
Reactions:
Posts: 7618
Joined: December 30th, 2011, 6:00 pm
Answers: 82
Contact:

Interaction instance not requesting state.

Post by Chain_Reaction » January 31st, 2021, 2:27 am

So I haven't messed around with animation in a while but I believe you are missing code to tell the statemachine to enter whichever state you are trying to run animations from.

You can do this before setting your actors or after I believe.

Code: Select all

stateMachineClient.EnterState('x', 'Enter');

User avatar
lyralei
Reactions:
Posts: 13
Joined: January 30th, 2021, 5:36 am

Interaction instance not requesting state.

Post by lyralei » January 31st, 2021, 4:22 am

Chain_Reaction wrote:
January 31st, 2021, 2:27 am
So I haven't messed around with animation in a while but I believe you are missing code to tell the statemachine to enter whichever state you are trying to run animations from.

You can do this before setting your actors or after I believe.

Code: Select all

stateMachineClient.EnterState('x', 'Enter');
Hiya! Thanks for the reply! :)

I actually added the EnterState in another function, which I totally forgot to share, but I can indeed try the enter and then request, see what happens.

Thanks again! I'll let you know how it goes

User avatar
lyralei
Reactions:
Posts: 13
Joined: January 30th, 2021, 5:36 am

Interaction instance not requesting state.

Post by lyralei » January 31st, 2021, 6:48 am

So... nothing was wrong with the code actually... it was more my own stupidity :p

of course, homework can only be done by children and teens, so EA put a parameter in the Jazz that does exactly that. But I had only tested this with adult sims so while the state was being able to be called, the jazz script would see that the actor was an adult and not a teen.

So removing that restriction inside the jazz script did the trick! I had to edit it anyways since homework and reading someone elses journal is of course a bit of a different animation loop ;)

Thanks for your help again btw!

Post Reply