Changing what is shown on a text panel - c#

I'm trying to make a C# script for unity to create dialogue using 'Ink.Runtime' and this procedure in the code is attempting to switch the text to a new line when the condition is met. But when I attempt to run the script the following error is displayed:
Assets\C# Scripts\DialogueManager.cs(60,13): error CS0103: The name 'dialogueText' does not exist in the current context
Here's the relevant string of code written below
private void ContinueStory()
{
if (currentStory.canContinue)
{
dialogueText.text = currentStory.Continue();
}
else
{
ExitDialogueMode();
}
}
I think an issue may be that I was previously using the new input system but switched back to the old one and may have forgotten to change this string in using that input system. I'm relatively new to programming in C# and so help would be much appriciated!

It's tough from the small snippet provided but from the error it looks like the assignment is outside the context of where your dialogText is accessible. Look at your modifier on how you instantiated the dialogText object and either change it to internal or public or pass the object in the method so it is within the context you are trying to change it.

Related

VS 2015 C# AsyncExtension.cs not found

I haven't been able to find any information on this online. I'm debugging an console application, trying to step through some code. When I go to step over I get a source not found error. It says "AsyncExtension.cs not found" and then gives me some details. It says "You need to find AsyncExtension.cs to view the source for the current call stack frame". I'm working in VS2015. I'm assuming something async is happening behind the scenes, its erroring at some point but can't give me the specific details because it can't find the assembly containing AsyncExtension. But I don't know what this is, where to get it, etc. The code in particular I'm trying to step over is below. But I seem to get this at various points, and even when debugging other projects under the same solution.
Line of code:
var newObject = JsonConvert.DeserializeObject<HIDPMessage>(message.ToString());
HIDPMessage:
public class HIDPMessage
{
public string version { get; set; }
[Newtonsoft.Json.JsonProperty]
public string header { get; set; }
[Newtonsoft.Json.JsonProperty]
private Data Data { get; set; }
}
Not sure what you are trying to do but the code you have provided would not normally have any references to anything called AsyncExtension.cs. However your attempt to deserialize message could cause a JsonReaderException.
I'm guessing that "message" is some object that contains properties in common with HIDPMessage type and that you are trying to extract those into a new object, if so message.ToString(), unless overridden will just return the name of the type.
You need to serialize the object to a json string and use the json string instead of message.ToString();
Thanks for the input guys, you were right my code for deserializing was a little off. It turns out this app was built using VS2017 and some components from the Azure SDK were missing. I tried a manual install of the SDK but it wouldn't work - upgrading to 2017 fixed it, but I'm kinda surprised I had to upgrade just to get it to work.
I appreciate the feedback on the serialization stuff as well. This is a new-ish area for me and I'm still learning.

Neo.ApplicationFramework "The name ... does not exist in the current context"

I'm dabbling in C# to write some scripts in what is otherwise a graphical machine interface programming environment (Beijer's iX Developer). The HMI is monitoring 'tags' (variables) in a PLC (programmable logic controller).
When tag Controller1_M18 turns on I want to print a report and then reset the tag. This code I'm putting in the Tags Script module is giving me error "The name 'PrintReport' does not exist in the current context". Can anyone give me guidance in fixing it?
namespace Neo.ApplicationFramework.Generated
{
using System.Windows.Forms;
using System;
using System.Drawing;
using Neo.ApplicationFramework.Tools;
using Neo.ApplicationFramework.Common.Graphics.Logic;
using Neo.ApplicationFramework.Controls;
using Neo.ApplicationFramework.Interfaces;
using Neo.ApplicationFramework.Tools.Reporting;
public partial class Report_Functions
{
void Controller1_M18_ValueOn(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
// Print the report.
PrintReport("BatchReport1");
// Reset the tag.
Globals.Tags.Controller1_M18.ResetTag();
}
}
}
The sparse scripting help file gives the information
Namespace: Neo.ApplicationFramework.Tools.Reporting
Assembly: ToolsCF (in ToolsCF.dll) Version: 2.15.5714.0
Syntax
public void PrintReport(
string reportName
)
ToolsCF.dll is present in the application folder along with all the others.
The method you are attempting to call, PrintReport simply doesn't exist in the class you have created. Either you have copy pasted this code from somewhere and missed that out or you are trying to reference a method in a different class. It's impossible to tell any more than this from the limited information provided.
Neo.ApplicationFramework.Generated.Globals.Reports.PrintReport("BatchReport1");

sharing a static class with a DLL in C# without passing a reference

VS2012 for desktop .net framework 4.5 normal windows forms applications, not WPF
Hello, I tried to search for an answer, but I'm not sure of the correct terminology. I've managed to break my code, and can't understand what I've done wrong. (i didn't think i had changed anything, but ...)
I have a solution which contains 2 projects. The first project is an executable program, and the second is a DLL, which is loaded at run time and used by the first project.
the first project contains a form, and a static class with public static strings in the same namespace. (and some other unconnected classes). specifically:
namespace project1_namespace
{
static class settings
{
public static string some_words = "some words in a string";
}
class dll_callback{
//.. some public methods here
}
dll_callback dllcallback; // instance is initialised in the code (not shown)
Form form;
public partial class frm_splash : Form
{
private void frm_splash_FormClosing(object sender, FormClosingEventArgs e)
{
// this function actually loads the DLL, ensuring its the last step
//... some error checking code removed for brevity
Assembly assembly = Assembly.LoadFrom("c:\dllpath\project2.dll");
Type type_init = assembly.GetType("project2_class");
object init = Activator.CreateInstance(type_init, form, dllcallback);
//... some error checking code removed for brevity
}// end method
}// end form class
}// end namespace
when the form is closing, the method shown above is called which calls the second projects class project2_class constructor.
in project 2, the DLL, there is:
namespace project2_namespace
{
// how did i get this working to reference "settings" class from project 1??
public class project2_class
{
public project2_class(project2_namespace.Form1 form_ref, object callback)
{
settings.some_words = "the words have changed";
//... some more stuff
}
}
}
Now, i was experimenting with some code in an entirely different part of project2, and VS2012 suddenly started refusing to compile stating:
error CS0103: The name 'settings' does not exist in the current context
the standard solution to this appears to be to add a reference to project2, but that would create circular dependencies because project 1 calls 2 as a DLL.
I really honestly don't think i had changed anything relevant to this, but also clearly I have.
looking at it, i cant see how project 2 would have access to a class in project 1 without a reference, but the list of arguments to the project2_class constructor doesn't include one, and I am absolutely positive that it hasn't changed (and I cant change it for backwards compatibility reasons).
would really appreciate help with this, as its been a lot of work to get this working.
as a side note, I've definitely learned my lesson about not using source control. and not making "how this works" comments instead of "what this does" comments.
may dynamic help you? You can not get the setting string at complie time.

Can't load model using ContentTypeReader

I'm writing a game where I want to use ContentTypeReader. While loading my model like this:
terrain = Content.Load<Model>("Text/terrain");
I get following error:
Error loading "Text\terrain". Cannot find ContentTypeReader
AdventureGame.World.HeightMapInfoReader,AdventureGame,Version=1.0.0.0,Culture=neutral.
I've read that this kind of error can be caused by space's in assembly name so i've already removed them all but exception still occurs.
This is my content class:
[ContentTypeWriter]
public class HeightMapInfoWriter : ContentTypeWriter<HeightmapInfo>
{
protected override void Write(ContentWriter output, HeightmapInfo value)
{
output.Write(value.getTerrainScale);
output.Write(value.getHeight.GetLength(0));
output.Write(value.getHeight.GetLength(1));
foreach (float height in value.getHeight)
{
output.Write(height);
}
}
public override string GetRuntimeType(TargetPlatform targetPlatform)
{
return
"AdventureGame.World.Heightmap,AdventureGame,Version=1.0.0.0,Culture=neutral";
}
public override string GetRuntimeReader(TargetPlatform targetPlatform)
{
return
"AdventureGame.World.HeightMapInfoReader,AdventureGame,Version=1.0.0.0,Culture=neutral";
}
}
Does anyone meed that kind of error before?
I have been encountering the same problem for a week, and finally decided to do a quick check on the whole "assembly" part.
I found a fix!
Essentially, when you go into AssemblyInfo.cs, you will see all the properties(ie Title, Description, etc.)
The Title, sadly made by XNA, is NOT what your runtime reader refers to. Its actually getting the initial name of the project, which it uses to track back to your application (exe) file in your project. Try either re-making your project from scratch, making sure to keep your namespace the same as your project and never change it , or give a go at re-naming your exe file, found in the debug/obj folder in your project(i believe). hope I helped!
-Will

One web application, two namespaces

I have one web application with two projects:
Project "Website"
Using CMS;
namespace Web
{
}
Project "CMS"
namespace CMS
{
public class Functions
{
}
}
Then I want to be able to use CMS.Functions.MyMethod() inside Website.Web.
Im having some problem with this.. Inside the "Website" project I have added "CMS" as a reference and I have also added Using CMS; and even tho the intellisense picks up CMS.Functions I get an error! The word CMS gets underlined blue and I get the message:
The name 'CMS' does not exist in the current context
What am I missing out? Its so weird becuase I can write CMS.Functions and the "Functions" part comes up in the intellisense but when I finish the line the word CMS gets underlined blue and I get the error even tho I got a reference and a Using statement.
From the sound of it, you want to make your Functions class methods to be static
namespace CMS
{
public class Functions
{
public static void MyMethod(){
//do stuff
}
}
}
The most likely cause is that you have not added a reference to the CMS project to your main project. That is the only time that I get the exception about the name not existing in the current context.

Categories

Resources