hi I'm a complete newbie when it comes to coding and as I followed a tutorial on YouTube on how to create a coloring game and followed the instructions to a tee I tried renaming my instance name of the symbol but I still get the errors
}
private function addEvents(...objects){
for(var i:Number=0; i<objects.length; i++){
objects[i].addEventListener(MouseEvent.CLICK, selectObject);
}
}
private function selectedObject(e:MouseEvent):void{
myObject = e.target;
ColorPickerMc.spectrum.addEventListener(MouseEvent.MOUSE_MOVE, updateColor);
}
private function backtoMainScreen(e:MouseEvent) {
MovieClip(stage.getChildAt(0)).gotoAndStop("Intro");
}
private function updateColor(e:MouseEvent){
hexaColor = "0x"+bitmapDt.getPixel(ColorPickerMc.spectrum.mouseX, ColorPickerMc.spectrum.mouseY).toString(16);
ct.color = hexaColor;
myObject.transform.colorTransform = ct;
}
private function freezeColor(e:MouseEvent){
myObject.transform.colorTransform = ct;
ColorPickerMc.spectrum.removeEventListener(MouseEvent.MOUSE_MOVE, updateColor);
}
the problems are on line 29, line 34, line 46, and line 50
and the Youtube link: https://www.youtube.com/watch?v=sxig7-ZVdLw from 37:00 to 39:00 I should have the desired results just by following the instructions, but I got these errors how do i fix these?
Related
I'm trying to write a very simple C# program in VS2015. I keep getting a message "The name (variable) does not exist in the current context." This is true for both my bool variable and string variable.
namespace PTouch
{
public class PTouch
{
bool lb_rc;
string strLabel;
lb_rc = false;
strLabel = "C:\BenchTop10\Standard 1in.lbx";
bpac.Document doc = new Document();
lb_rc = doc.Open("C:\BenchTop10\Standard 1in.lbx");
if lb_rc != false
{
doc.StartPrint("", 0);
doc.PrintOut(1, 0);
doc.EndPrint();
doc.Close();
}
else
{
MessageBox.Show("Open Error: " + doc.ErrorCode);
}
}
}
There are probably several problems with this code, but the first one is error about the variables not existing in the current context.
Any assistance is greatly appreciated.
I just discovered the problem... All the code has to be inside of a method, not just the class. I added a method to the class,
public void PrintLabel()
{ bool lb_rc; ... }
All errors cleared up, except MessageBox...
Thank you,
Tracy
public static void CalibrateLoop()
{
communicator comport = new communicator();
while ( Variables.calibrating )
{
Thread.Sleep(500);
if (comport.connect(9600, "VRCONNECTREQUEST", 1, 0, 0))
{
form2.label7.Text = "Connection Successful - Connected to " + comport.port;
}
else
{
Form2.Hide();
var form1 = new Form1();
form1.Closed += (s, args) => Form1.Close();
form1.Show();
}
//label2.Text = comport.message(2, 0, 0);
}
//Variables.minHand[0] = 20;
}
I made this real quick simple piece of code in communicator.cs, the issue is that it refuses to edit the "label7.text" and also the "form2.hide()" doesn't seem to work. The Label7 is located in form2.
Anyone can help me out with this issue? been struggeling to find an answer allover internet
Give proper Reference to that particular file or include a respective Namespace.
In player.hx:
public function new(X, Y, _upKey:String, _downKey:String){
super(X, Y);
makeGraphic(20, 20, FlxColor.RED);
immovable = true;
}
In PlayState.hx:
override public function create():Void
{
super.create();
add(new Enemy(300, FlxG.height - 20, 10, 20));
add(new Enemy(500, FlxG.height - 40, 10, 40));
add(player = new Player(60, FlxG.height - 40, "UP", "DOWN"));
}
It returns to me with the errors "Unknown identifier: upKey" and "Unknown identifier: downKey" in the Player.hx file, even after I already set those in the function. How do I fix this?
Function arguments are only available in that particular function (this is known as the scope of the variable) - so just because your constructor has arguments named upKey and downKey, that doesn't mean you can also automatically use them in another function like update().
To be able to do that, you need to save the arguments to member variables of the Player class:
class Player extends FlxSprite
{
var upKey:String;
var downKey:String;
public function new(X, Y, upKey:String, downKey:String)
{
super(X, Y);
this.upKey = upKey;
this.downKey = downKey;
}
override public function update():Void
{
super.update();
trace(upKey, downKey);
}
}
No matter which printer I select, I get "Print-job failed: Unsupported document format "application/pdf".
I am trying to print on HP printers only.
I see no place in code to change the output type.
I am using UISimpleTextFormatter to format the string.
Not sure how to get around this one.
Edit : Code below is straight up from Miguel's example. with the only difference being, I tried out the markupformatter to see whether it gets output in a different format than application/pdf.
The print dialog comes up with the list of HP printers, I select a printer but nothing gets printed and in debug mode, the error specified at the top gets logged.
Other than UIPrintInfoOutputType.General, I have also tried UIPrintInfoOutputType.GrayScale but with the same effect.
public partial class AppDelegate : UIApplicationDelegate
{
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window.MakeKeyAndVisible ();
var button = UIButton.FromType (UIButtonType.RoundedRect);
button.Frame = new RectangleF (100, 100, 120, 60);
button.SetTitle ("Print", UIControlState.Normal);
button.TouchDown += delegate {
Print ();
};
window.AddSubview (button);
return true;
}
void Print ()
{
var printInfo = UIPrintInfo.PrintInfo;
printInfo.JobName = "Test :";
printInfo.OutputType = UIPrintInfoOutputType.General;
printInfo.JobName = "Test: My first Print Job";
/*
var textFormatter = new UISimpleTextPrintFormatter ("Once upon a time...") {
StartPage = 0,
ContentInsets = new UIEdgeInsets (72, 72, 72, 72),
MaximumContentWidth = 6 * 72,
};
*/
var htmlFormatter = new UIMarkupTextPrintFormatter("<html><body>Test : Hi There!!</body></html>");
htmlFormatter.StartPage = 0;
htmlFormatter.ContentInsets = new UIEdgeInsets (72, 72, 72, 72); // 1 inch margins
htmlFormatter.MaximumContentWidth = 6 * 72;
var printer = UIPrintInteractionController.SharedPrintController;
printer.PrintInfo = printInfo;
printer.PrintFormatter = htmlFormatter;
printer.ShowsPageRange = true;
printer.Present (true, (handler, completed, err) => {
if (!completed && err != null){
Console.WriteLine ("error");
}
});
}
public override void OnActivated (UIApplication application)
{
}
}
I was expecting the print dialog to come up with only the air print enabled printers. But it comes up with non airprint enabled HP printers as well. That amde me think, it could print to those printers and that they are air print enabled.
But that was not the case.
Using C# 4 in a Windows console application that continually reports progress how can I make the "redraw" of the screen more fluid?
I'd like to do one of the following:
- Have it only "redraw" the part of the screen that's changing (the progress portion) and leave the rest as is.
- "Redraw" the whole screen but not have it flicker.
Currently I re-write all the text (application name, etc.). Like this:
Console.Clear();
WriteTitle();
Console.WriteLine();
Console.WriteLine("Deleting:\t{0} of {1} ({2})".FormatString(count.ToString("N0"), total.ToString("N0"), (count / (decimal)total).ToString("P2")));
Which causes a lot of flickering.
Try Console.SetCursorPosition. More details here: How can I update the current line in a C# Windows Console App?
static void Main(string[] args)
{
Console.SetCursorPosition(0, 0);
Console.Write("################################");
for (int row = 1; row < 10; row++)
{
Console.SetCursorPosition(0, row);
Console.Write("# #");
}
Console.SetCursorPosition(0, 10);
Console.Write("################################");
int data = 1;
System.Diagnostics.Stopwatch clock = new System.Diagnostics.Stopwatch();
clock.Start();
while (true)
{
data++;
Console.SetCursorPosition(1, 2);
Console.Write("Current Value: " + data.ToString());
Console.SetCursorPosition(1, 3);
Console.Write("Running Time: " + clock.Elapsed.TotalSeconds.ToString());
Thread.Sleep(1000);
}
Console.ReadKey();
}
I know this question is a bit old but I found if you set Console.CursorVisible = false then the flickering stops as well.
Here's a simple working demo that shows multi-line usage without flickering. It shows the current time and a random string every second.
private static void StatusUpdate()
{
var whiteSpace = new StringBuilder();
whiteSpace.Append(' ', 10);
var random = new Random();
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var randomWord = new string(Enumerable.Repeat(chars, random.Next(10)).Select(s => s[random.Next(s.Length)]).ToArray());
while (true)
{
Console.SetCursorPosition(0, 0);
var sb = new StringBuilder();
sb.AppendLine($"Program Status:{whiteSpace}");
sb.AppendLine("-------------------------------");
sb.AppendLine($"Last Updated: {DateTime.Now}{whiteSpace}");
sb.AppendLine($"Random Word: {randomWord}{whiteSpace}");
sb.AppendLine("-------------------------------");
Console.Write(sb);
Thread.Sleep(1000);
}
}
The above example assumes your console window is blank to start. If not, make sure to use Console.Clear() first.
Technical Note:
SetCursorPosition(0,0) places the cursor back to the top (0,0) so the next call to Console.Write will start from line 0, char 0. Note, it doesn't delete the previous content before writing. As an example, if you write "asdf" over a previous line such as "0123456", you'll end up with something like "asdf456" on that line. For that reason, we use a whiteSpace variable to ensure any lingering characters from the previous line are overwritten with blank spaces. Adjust the length of the whiteSpace variable to meet your needs. You only need the whiteSpace variable for lines that change.
Personal Note:
For my purposes, I wanted to show the applications current status (once a second) along with a bunch of other status information and I wanted to avoid any annoying flickering that can happen when you use Console.Clear(). In my application, I run my status updates behind a separate thread so it constantly provides updates even though I have numerous other threads and long running tasks going at the same time.
Credits:
Thanks to previous posters and dtb for the random string generator used in the demo.
How can I generate random alphanumeric strings in C#?
You could try to hack something together using the core libraries.
Rather than waste your time for sub-standard results, I would check out this C# port of the ncurses library (which is a library used for formatting console output):
Curses Sharp
I think you can use \r in Windows console to return the beginning of a line.
You could also use SetCursorPosition.
I would recommend the following extension methods. They allow you to use a StringBuilder to refresh the console view without any flicker, and also tidies up any residual characters on each line
The Problem: The following demo demonstrates using a standard StringBuilder, where updating lines that are shorter than the previously written line get jumbled up. It does this by writing a short string, then a long string on a loop:
public static void Main(string[] args)
{
var switchTextLength = false;
while(true)
{
var sb = new StringBuilder();
if (switchTextLength)
sb.AppendLine("Short msg");
else
sb.AppendLine("Longer message");
sb.UpdateConsole();
switchTextLength = !switchTextLength;
Thread.Sleep(500);
}
}
Result:
The Solution: By using the extension method provided below, the issue is resolved
public static void Main(string[] args)
{
var switchTextLength = false;
while(true)
{
var sb = new StringBuilder();
if (switchTextLength)
sb.AppendLineEx("Short msg");
else
sb.AppendLineEx("Longer message");
sb.UpdateConsole();
switchTextLength = !switchTextLength;
Thread.Sleep(500);
}
}
Result:
Extension Methods:
public static class StringBuilderExtensions
{
/// <summary>
/// Allows StrinbBuilder callers to append a line and blank out the remaining characters for the length of the console buffer width
/// </summary>
public static void AppendLineEx(this StringBuilder c, string msg)
{
// Append the actual line
c.Append(msg);
// Add blanking chars for the rest of the buffer
c.Append(' ', Console.BufferWidth - msg.Length - 1);
// Finish the line
c.Append(Environment.NewLine);
}
/// <summary>
/// Combines two StringBuilders using AppendLineEx
/// </summary>
public static void AppendEx(this StringBuilder c, StringBuilder toAdd)
{
foreach (var line in toAdd.ReadLines())
{
c.AppendLineEx(line);
}
}
/// <summary>
/// Hides the console cursor, resets its position and writes out the string builder
/// </summary>
public static void UpdateConsole(this StringBuilder c)
{
// Ensure the cursor is hidden
if (Console.CursorVisible) Console.CursorVisible = false;
// Reset the cursor position to the top of the console and write out the string builder
Console.SetCursorPosition(0, 0);
Console.WriteLine(c);
}
}
I actually had this issue so I made a quick simple method to try and eliminate this.
static void Clear(string text, int x, int y)
{
char[] textChars = text.ToCharArray();
string newText = "";
//Converts the string you just wrote into a blank string
foreach(char c in textChars)
{
text = text.Replace(c, ' ');
}
newText = text;
//Sets the cursor position
Console.SetCursorPosition(x, y);
//Writes the blank string over the old string
Console.WriteLine(newText);
//Resets cursor position
Console.SetCursorPosition(0, 0);
}
It actually worked surprisingly well and I hope it may work for you!
Naive approach but for simple applications is working:
protected string clearBuffer = null; // Clear this if window size changes
protected void ClearConsole()
{
if (clearBuffer == null)
{
var line = "".PadLeft(Console.WindowWidth, ' ');
var lines = new StringBuilder();
for (var i = 0; i < Console.WindowHeight; i++)
{
lines.AppendLine(line);
}
clearBuffer = lines.ToString();
}
Console.SetCursorPosition(0, 0);
Console.Write(clearBuffer);
Console.SetCursorPosition(0, 0);
}
Console.SetCursorPosition(0, 0); //Instead of Console.Clear();
WriteTitle();
Console.WriteLine();
Console.WriteLine("Deleting:\t{0} of {1} ({2})".FormatString(count.ToString("N0")