Replies: 8 (Who?), Viewed: 364 times.
Test Subject
Original Poster
#1 Old 24th Jun 2020 at 11:07 PM
Default I really need help with making interactions!!!
Hey guys, So I am really stuck right now. I need help with interactions, when I try to create an interaction with pure script modding; I always get errors. I have followed many tutorials and it hasn't worked yet; so I would be glad if someone were to help me with this.
Advertisement
Field Researcher
#2 Old 25th Jun 2020 at 5:09 AM
Quote:
Originally Posted by SimShady19
Hey guys, So I am really stuck right now. I need help with interactions, when I try to create an interaction with pure script modding; I always get errors. I have followed many tutorials and it hasn't worked yet; so I would be glad if someone were to help me with this.


We're happy to help, but you're going to need to give a bit more detail.

What are the errors you're getting, and what is the code that you think is causing those errors?

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Test Subject
Original Poster
#3 Old 26th Jun 2020 at 10:11 PM
Quote:
Originally Posted by gamefreak130
We're happy to help, but you're going to need to give a bit more detail.

What are the errors you're getting, and what is the code that you think is causing those errors?


Thank you so much for responding!, The issue is when I put what I wanted my Interaction to be named it sends and an error. I do not know what exactly I am doing wrong but I will show you.


using System;
using System.Collections.Generic;
using System.Text;
using Sims3.Gameplay;
using Sims3.Gameplay.Actors;
using Sims3.Gameplay.Autonomy;
using Sims3.Gameplay.EventSystem;
using Sims3.Gameplay.Interactions;
using Sims3.Gameplay.Utilities;
using Sims3.SimIFace;
using Sims3.UI;

namespace SimShady19.Royalgreeting.Common //Use your own unique namespace here
{
public class DemoClass
{
[Tunable]
protected static bool kInstantiator = false;
private static EventListener sSimInstantiatedListener = null;
//private static EventListener sSimAgedUpListener = null; //Optional age transition listener

static DemoClass()
{
World.OnWorldLoadFinishedEventHandler += new EventHandler(OnWorldLoadFinishedHandler);
}

public static void OnWorldLoadFinishedHandler(object sender, System.EventArgs e)
{
try
{
foreach (Sim sim in Sims3.Gameplay.Queries.GetObjects<Sim>())
{
if (sim != null)
{
AddInteractions(sim);
}
}
}
catch (Exception exception)
{
Exception(exception);
}
sSimInstantiatedListener = EventTracker.AddListener(EventTypeId.kSimInstantiated, new ProcessEventDelegate(OnSimInstantiated));
//sSimAgedUpListener = EventTracker.AddListener(EventTypeId.kSimAgeTransition, new ProcessEventDelegate(OnSimInstantiated));
}

protected static ListenerAction OnSimInstantiated(Event e)
{
try
{
Sim sim = e.TargetObject as Sim;
if (sim != null)
{
AddInteractions(sim);
}
}
catch (Exception exception)
{
Exception(exception);
}
return ListenerAction.Keep;
}

public static void AddInteractions(Sim sim)
{
//if (sim.SimDescription.TeenOrAbove) //Optional conditions for adding interaction
//{
foreach (InteractionObjectPair pair in sim.Interactions)
{
if (pair.InteractionDefinition.GetType() == Royalgreeting.Singleton.GetType())
{
return;
}
}
sim.AddInteraction(Royalgreeting.Singleton);
//}
}

public static bool Exception(Exception exception)
{
try
{
return ((IScriptErrorWindow)AppDomain.CurrentDomain.GetData("ScriptErrorWindow")).DisplayScriptError(null, exception);
}
catch
{
WriteLog(exception);
return true;
}
}
public static bool WriteLog(Exception exception)
{
try
{
new ScriptError(null, exception, 0).WriteMiniScriptError();
return true;
}
catch
{
return false;
}
}

private sealed class ShowNotification : ImmediateInteraction<Sim, Sim>
{
public static readonly InteractionDefinition Singleton = new Definition();
protected override bool Run()
{
base.Actor.ShowTNSIfSelectable("Royal greeting", StyledNotification.NotificationStyle.kSimTalking);
return true;
StyledNotification.Show(new StyledNotification.Format(base.Actor.Name + " has clicked on " + base.Target.Name,
StyledNotification.NotificationStyle.kGameMessagePositive));
return true;
}
[DoesntRequireTuning]
private sealed class Definition : ImmediateInteractionDefinition<Sim, Sim, ShowNotification>
{
protected override string GetInteractionName(Sim actor, Sim target, InteractionObjectPair interaction)
{
return "Royal greeting";
}
protected override bool Test(Sim actor, Sim target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
return true;
//return (actor.SimDescription.Age == target.SimDescription.Age); //Optional test for visibility of interaction
return true; //comment out or delete if using test
}
//public override string[] GetPath(bool bPath) //Optional path for interaction
//{
// return new string[] { "MyStuff Options..." };
//}
}
}
}
}
Trainee Moderator
staff: trainee moderator
#4 Old 26th Jun 2020 at 11:26 PM
Hey there,
I think what the problem is, is that you are trying to add an interaction called Royalgreeting, but the name of your interaction (the name of the class) is called ShowNotification.
You're going to want to change that to Royalgreeting (or RoyalGreeting if you want it to be neater, but don't forget to add the capital G when you do the AddInteraction).
You will also have to change the name of the interaction in the InteractionDefinition where it says:
Code:
private sealed class Definition : ImmediateInteractionDefinition<Sim, Sim, ShowNotification> 

You will need to change it to:
Code:
private sealed class Definition : ImmediateInteractionDefinition<Sim, Sim, RoyalGreeting> 

The GetInteractionName() function is just for the string that appears in game when you click on the object/sim. Whereas the name of the interaction's class is what the code recognises when you want to do AddInteraction(SomeInteraction.singleton)
I know your code is just in the early stages for testing, but I just want to point out in your Run() function, you have a ShowNotification method after "return true" which won't show up, so you want to delete that first return true; command to have everything execute.

Finally, when posting code here, it's helpful to use the [ code] [ /code] tags (but without spaces :p) to make it easier to read, as you can see in this post, and figure out the problem.
Hope this helps!
Test Subject
Original Poster
#5 Old 28th Jun 2020 at 7:12 AM
Quote:
Originally Posted by zoe22
Hey there,
I think what the problem is, is that you are trying to add an interaction called Royalgreeting, but the name of your interaction (the name of the class) is called ShowNotification.
You're going to want to change that to Royalgreeting (or RoyalGreeting if you want it to be neater, but don't forget to add the capital G when you do the AddInteraction).
You will also have to change the name of the interaction in the InteractionDefinition where it says:
Code:
private sealed class Definition : ImmediateInteractionDefinition<Sim, Sim, ShowNotification> 

You will need to change it to:
Code:
private sealed class Definition : ImmediateInteractionDefinition<Sim, Sim, RoyalGreeting> 

The GetInteractionName() function is just for the string that appears in game when you click on the object/sim. Whereas the name of the interaction's class is what the code recognises when you want to do AddInteraction(SomeInteraction.singleton)
I know your code is just in the early stages for testing, but I just want to point out in your Run() function, you have a ShowNotification method after "return true" which won't show up, so you want to delete that first return true; command to have everything execute.

Finally, when posting code here, it's helpful to use the [ code] [ /code] tags (but without spaces :p) to make it easier to read, as you can see in this post, and figure out the problem.
Hope this helps!


Thank you! it actually helped,but can anyone help me because;my interaction is not showing up in game.
Virtual gardener
staff: administrator
#6 Old 28th Jun 2020 at 9:43 AM Last edited by Lyralei : 28th Jun 2020 at 9:55 AM.
[Tunable]
protected static bool kInstantiator = false;Have you done the Instantiator XML thingy? It's described right here:

https://modthesims.info/wiki.php?ti...ripting_Modding
(See Writing The XML File and the Building The Package)

If you're sure that works, then there's always "printing" the heck out of the code :p So this is what I usually do, I make a function like:

Code:
         public static void print(string text)
        {
            SimpleMessageDialog.Show("Lyralei's Sewing Table:", text);
        }
And then in your Run() function and even in the AddInteractions() and OnSimInstantiated() functions, you just add something like:
Code:
print("Debug text here!");
Make sure it's all different 'print texts' because else you have a super hard time figuring out at which line it's crashing. So you could even go as far as "Line: 2" and then the next print being "Line: 3". Debugging is your friend in need! 
Test Subject
Original Poster
#7 Old 1st Jul 2020 at 1:06 AM
Quote:
Originally Posted by Lyralei
[Tunable]
protected static bool kInstantiator = false;Have you done the Instantiator XML thingy? It's described right here:

https://modthesims.info/wiki.php?ti...ripting_Modding
(See Writing The XML File and the Building The Package)

If you're sure that works, then there's always "printing" the heck out of the code :p So this is what I usually do, I make a function like:

Code:
         public static void print(string text)
        {
            SimpleMessageDialog.Show("Lyralei's Sewing Table:", text);
        }
And then in your Run() function and even in the AddInteractions() and OnSimInstantiated() functions, you just add something like:
Code:
print("Debug text here!");
Make sure it's all different 'print texts' because else you have a super hard time figuring out at which line it's crashing. So you could even go as far as "Line: 2" and then the next print being "Line: 3". Debugging is your friend in need! 

Thanks I hope this works ,But I think my Xml file is the issue. I do not know how to fully write one.
Virtual gardener
staff: administrator
#8 Old 1st Jul 2020 at 9:36 AM
Have you checked out this tutorial? (See "witing the XML" and "Building the package" : https://www.modthesims.info/wiki.ph...ripting_Modding  )

This bit is extra important for you:

Quote:
Open a text editor and paste the following:

Code:
<?xml version="1.0" encoding="utf-8"?>
<base>
  <Current_Tuning>
    <kInstantiator value="True" />
  </Current_Tuning>
</base&gt


Of course you have noticed the kInstantiator variable from the code. Save the file. You can close the text editor now as you won't need it again.
And:

Quote:
Now on to the tuning XML (in your package):
  • Click on Resource -> Add... once more
  • Choose _XML 0x0333406C for Type.
  • Enter 0 for the Group.
  • Here the Instance value is important, so get the Name right. It must be the namespace plus class name of the class where the tunable variable is located. In the case of this tutorial that's TwoBTech.Pausinator.
  • With the _XML resource selected, choose Resource->Import->From file... and this time import the XML text file you created. S3PE will show the content of the XML resource in its preview window. Make sure that the content begins with an angle bracket and not with some unintelligible characters. That is a common error.
Test Subject
Original Poster
#9 Old Yesterday at 8:11 PM
Quote:
Originally Posted by Lyralei
Have you checked out this tutorial? (See "witing the XML" and "Building the package" : https://www.modthesims.info/wiki.ph...ripting_Modding  )

This bit is extra important for you:

And:

I really do not know if I did it correctly. If someone knows please correct me.
Screenshots
Back to top