C
C#ā€¢2y ago
Bugz000

ā” How to structure funcs that calls funcs from static cast

i am getting error CS0120 - https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0120 example 2 is my situation (and solution), but should i invoke an instance of itself in Main() - to call a func, and i'd need to invoke another instance there to call further funcs? if nothing is passed then how does the contents of main (thus the instance) get handed to func1 to know the instance to call func2... in my mind these will all be running their own main() instance, is it not recursive? i'm misunderstanding something fundermental here
125 Replies
Bugz000
Bugz000OPā€¢2y ago
using System;
using System.Collections;
using System.Collections.Generic;

class TUI
{
private void Append(string input)
{
Type type = typeof(ConsoleColor);
Dictionary<int, string> ConsoleColors = new Dictionary<int, string>();
var loopCounter = 0;
foreach (var name in Enum.GetNames(type))
{
loopCounter++;
ConsoleColors[loopCounter] = name;
}
foreach (char chr in input)
{
if (((int)chr) <= 15)
{
Console.ForegroundColor = (ConsoleColor)Enum.Parse(type, ConsoleColors[(int)chr]);
continue;
}
Console.Write(chr);
}
Console.Write("\n");
}
private int rand(int low, int high)
{
Random rnd = new Random();
int output = rnd.Next(low, high);
return output;
}
private char Chr(int input)
{
char ret = Convert.ToChar(input);
return ret;
}
private void intro()
{
int col = rand(2,15);
int col2 = rand(2,15);
int col3 = rand(2,15);
Append(col);
}
public void Main()
{
var Instance = new TUI();
Instance.intro();
}
}
using System;
using System.Collections;
using System.Collections.Generic;

class TUI
{
private void Append(string input)
{
Type type = typeof(ConsoleColor);
Dictionary<int, string> ConsoleColors = new Dictionary<int, string>();
var loopCounter = 0;
foreach (var name in Enum.GetNames(type))
{
loopCounter++;
ConsoleColors[loopCounter] = name;
}
foreach (char chr in input)
{
if (((int)chr) <= 15)
{
Console.ForegroundColor = (ConsoleColor)Enum.Parse(type, ConsoleColors[(int)chr]);
continue;
}
Console.Write(chr);
}
Console.Write("\n");
}
private int rand(int low, int high)
{
Random rnd = new Random();
int output = rnd.Next(low, high);
return output;
}
private char Chr(int input)
{
char ret = Convert.ToChar(input);
return ret;
}
private void intro()
{
int col = rand(2,15);
int col2 = rand(2,15);
int col3 = rand(2,15);
Append(col);
}
public void Main()
{
var Instance = new TUI();
Instance.intro();
}
}
ero
eroā€¢2y ago
what line are you getting that error on? also it doesn't make much sense to create an instance of the same class you're already an instance of
Bugz000
Bugz000OPā€¢2y ago
Bugz000
Bugz000OPā€¢2y ago
the three rand() calls i got messing with them because i made rand() static but then the values were held each time i need them to clear when the func call ends (private?)
ero
eroā€¢2y ago
how are you running/debugging this?
Bugz000
Bugz000OPā€¢2y ago
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /t:exe /out:blah.exe blah.cs
blah.exe
timeout 5
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /t:exe /out:blah.exe blah.cs
blah.exe
timeout 5
ero
eroā€¢2y ago
yeah that's a huge issue why aren't you using an IDE?
Bugz000
Bugz000OPā€¢2y ago
unnecessary bloat
ero
eroā€¢2y ago
it's... really not? what? the whole point of an ide is to properly assist you with coding
Bugz000
Bugz000OPā€¢2y ago
my code is very simple i fail to see why i'd need an IDE to get that much working
ero
eroā€¢2y ago
because there are already compile errors with that code
Bugz000
Bugz000OPā€¢2y ago
visual studio is 70 something gb these days isn't it?
ero
eroā€¢2y ago
that code shouldn't even be allowed to run in the first place what???? no, obviously not
Bugz000
Bugz000OPā€¢2y ago
it was last time i uninstalled it hahaha
ero
eroā€¢2y ago
then you installed a bunch of unnecessary components you can also just get VSCode, Fleet, or Rider
Bugz000
Bugz000OPā€¢2y ago
i don't see how this is relevant to CS0120
ero
eroā€¢2y ago
that error does not get thrown
Bugz000
Bugz000OPā€¢2y ago
literally says it 3 times
MODiX
MODiXā€¢2y ago
Ero#1111
REPL Result: Failure
using System;
using System.Collections;
using System.Collections.Generic;

Tui tui = new();
tui.Main();

Console.WriteLine("Success!");

class TUI
{
private void Append(string input)
{
Type type = typeof(ConsoleColor);
Dictionary<int, string> ConsoleColors = new Dictionary<int, string>();
var loopCounter = 0;
foreach (var name in Enum.GetNames(type))
{
loopCounter++;
ConsoleColors[loopCounter] = name;
}
foreach (char chr in input)
{
if (((int)chr) <= 15)
{
Console.ForegroundColor = (ConsoleColor)Enum.Parse(type, ConsoleColors[(int)chr]);
continue;
}
Console.Write(chr);
}
Console.Write("\n");
}
private int rand(int low, int high)
{
Random rnd = new Random();
int output = rnd.Next(low, high);
return output;
}
private char Chr(int input)
{
char ret = Convert.ToChar(input);
return ret;
}
private void intro()
{
int col = rand(2,15);
int col2 = rand(2,15);
int col3 = rand(2,15);
//Append(col);
}
public void Main()
{
var Instance = new TUI();
Instance.intro();
}
}
using System;
using System.Collections;
using System.Collections.Generic;

Tui tui = new();
tui.Main();

Console.WriteLine("Success!");

class TUI
{
private void Append(string input)
{
Type type = typeof(ConsoleColor);
Dictionary<int, string> ConsoleColors = new Dictionary<int, string>();
var loopCounter = 0;
foreach (var name in Enum.GetNames(type))
{
loopCounter++;
ConsoleColors[loopCounter] = name;
}
foreach (char chr in input)
{
if (((int)chr) <= 15)
{
Console.ForegroundColor = (ConsoleColor)Enum.Parse(type, ConsoleColors[(int)chr]);
continue;
}
Console.Write(chr);
}
Console.Write("\n");
}
private int rand(int low, int high)
{
Random rnd = new Random();
int output = rnd.Next(low, high);
return output;
}
private char Chr(int input)
{
char ret = Convert.ToChar(input);
return ret;
}
private void intro()
{
int col = rand(2,15);
int col2 = rand(2,15);
int col3 = rand(2,15);
//Append(col);
}
public void Main()
{
var Instance = new TUI();
Instance.intro();
}
}
Exception: CompilationErrorException
- The type or namespace name 'Tui' could not be found (are you missing a using directive or an assembly reference?)
- The type or namespace name 'Tui' could not be found (are you missing a using directive or an assembly reference?)
Compile: 761.116ms | Execution: 0.000ms | React with āŒ to remove this embed.
ero
eroā€¢2y ago
come on
Bugz000
Bugz000OPā€¢2y ago
if you got a compile error it's probably cause i omitted static on main() lol just put static back there it'll work
MODiX
MODiXā€¢2y ago
Ero#1111
REPL Result: Success
using System;
using System.Collections;
using System.Collections.Generic;

TUI tui = new();
tui.Main();

Console.WriteLine("Success!");

class TUI
{
private void Append(string input)
{
Type type = typeof(ConsoleColor);
Dictionary<int, string> ConsoleColors = new Dictionary<int, string>();
var loopCounter = 0;
foreach (var name in Enum.GetNames(type))
{
loopCounter++;
ConsoleColors[loopCounter] = name;
}
foreach (char chr in input)
{
if (((int)chr) <= 15)
{
Console.ForegroundColor = (ConsoleColor)Enum.Parse(type, ConsoleColors[(int)chr]);
continue;
}
Console.Write(chr);
}
Console.Write("\n");
}
private int rand(int low, int high)
{
Random rnd = new Random();
int output = rnd.Next(low, high);
return output;
}
private char Chr(int input)
{
char ret = Convert.ToChar(input);
return ret;
}
private void intro()
{
int col = rand(2,15);
int col2 = rand(2,15);
int col3 = rand(2,15);
//Append(col);
}
public void Main()
{
var Instance = new TUI();
Instance.intro();
}
}
using System;
using System.Collections;
using System.Collections.Generic;

TUI tui = new();
tui.Main();

Console.WriteLine("Success!");

class TUI
{
private void Append(string input)
{
Type type = typeof(ConsoleColor);
Dictionary<int, string> ConsoleColors = new Dictionary<int, string>();
var loopCounter = 0;
foreach (var name in Enum.GetNames(type))
{
loopCounter++;
ConsoleColors[loopCounter] = name;
}
foreach (char chr in input)
{
if (((int)chr) <= 15)
{
Console.ForegroundColor = (ConsoleColor)Enum.Parse(type, ConsoleColors[(int)chr]);
continue;
}
Console.Write(chr);
}
Console.Write("\n");
}
private int rand(int low, int high)
{
Random rnd = new Random();
int output = rnd.Next(low, high);
return output;
}
private char Chr(int input)
{
char ret = Convert.ToChar(input);
return ret;
}
private void intro()
{
int col = rand(2,15);
int col2 = rand(2,15);
int col3 = rand(2,15);
//Append(col);
}
public void Main()
{
var Instance = new TUI();
Instance.intro();
}
}
Console Output
Success!
Success!
Compile: 701.481ms | Execution: 63.841ms | React with āŒ to remove this embed.
ero
eroā€¢2y ago
no error gets thrown get an IDE code properly
Bugz000
Bugz000OPā€¢2y ago
i dont think that executed anything
ero
eroā€¢2y ago
and don't use .net framework (jesus christ) of course it did
Bugz000
Bugz000OPā€¢2y ago
because there's no static call
ero
eroā€¢2y ago
why would there be? if you truly want to stay IDE-less (do not, i beg you), at least install .net 7 (sdk and runtime) and use the dotnet run command instead of csc
Bugz000
Bugz000OPā€¢2y ago
you've answered 4 questions i didn't ask for and flat avoided the one question i did ask the 4 questions you answered had no relevance to the issue at hand
ero
eroā€¢2y ago
is this not the answer? there is no error being thrown
Bugz000
Bugz000OPā€¢2y ago
oh, must be fine then
ero
eroā€¢2y ago
also the compile error is on Append(col); because col is an int, but Append takes a string
Bugz000
Bugz000OPā€¢2y ago
i'll put it real simple i'm an old fart i do things oldschool, i don't like IDEs, it's not gonna happen, let it go the question i asked is from static main(), to call a non static func, i must invoke an instance of it - but then if that func calls another func, how does it get the context of what instance, given i had to invoke an instance to call the first func
ero
eroā€¢2y ago
instance methods can be called by instance methods there's absolutely nothing stopping them it's all the same instance after all
Bugz000
Bugz000OPā€¢2y ago
but how does it know
ero
eroā€¢2y ago
it just... does?
Bugz000
Bugz000OPā€¢2y ago
some voodoo behind the scenes?
ero
eroā€¢2y ago
no? it's one instance all those methods exist in the context of that one instance of course the methods get compiled together into your binary the program just knows "oh, this is an instance method" and can only be called when they're called on an instance of the class
Bugz000
Bugz000OPā€¢2y ago
so static main is run on startup because it's static but it's "orphan" because it was not invoked by anything, an instance is created within it (or above it) and then that instance can run, i figure relying on static to run the program was my mistake here
ero
eroā€¢2y ago
this is a pretty common pattern, actually you don't actually have any instance data in the class so technically you could mark everything static
Bugz000
Bugz000OPā€¢2y ago
thats what i was doing initially but it seems to hold persistent state between func calls, all the rand() calls returned the same number lol
ero
eroā€¢2y ago
but it's not uncommon to do
class Program
{
static void Main()
{
MyClass.Run();
}
}

class MyClass
{
public static Run()
{
MyClass instance = new();
// ...
}

// ...
}
class Program
{
static void Main()
{
MyClass.Run();
}
}

class MyClass
{
public static Run()
{
MyClass instance = new();
// ...
}

// ...
}
you create a new instance of Random every time you call rand Random, by default, takes the current time or something for the seed since the calls are so fast, the seed will be the same every time
Bugz000
Bugz000OPā€¢2y ago
oh ffs
ero
eroā€¢2y ago
if you truly truly don't want to get an ide (you are just plainly wrong here, by the way), please at least do this;
winget install Microsoft.DotNet.SDK.7 (installs the .NET 7.0 SDK)

dotnet new console (creates a new console project)

dotnet run (builds and runs the project)
winget install Microsoft.DotNet.SDK.7 (installs the .NET 7.0 SDK)

dotnet new console (creates a new console project)

dotnet run (builds and runs the project)
i am sincerely begging you to stop using .net framework most of its versions are out of support it's not cross platform (modern .NET is) and it's so much older and less performant
Bugz000
Bugz000OPā€¢2y ago
idk how to even get around that because if i do get it working and it trashes content after each run it won't even know if the instance exists prior, is that the only way to get a random number i can't do this i'm afraid, my w10 is broken no joke lol no microsoft store or "extra features" work
ero
eroā€¢2y ago
so reinstall
Bugz000
Bugz000OPā€¢2y ago
not so easy, it's a ML350E G8 windows 10 does NOT like to run on here baremetal well, it runs fine, it doesn't want to install
ero
eroā€¢2y ago
Microsoft
Download .NET (Linux, macOS, and Windows)
Free downloads for building and running .NET apps on Linux, macOS, and Windows. Runtimes, SDKs, and developer packs for .NET Framework, .NET, and ASP.NET.
Bugz000
Bugz000OPā€¢2y ago
This release is only compatible with Visual Studio 2022 (v17.4)
:/
ero
eroā€¢2y ago
irrelevant that's a hint for when you use vs at all
Bugz000
Bugz000OPā€¢2y ago
the compiler still works?
ero
eroā€¢2y ago
of course
Bugz000
Bugz000OPā€¢2y ago
any ideas where the compiler ends up
ero
eroā€¢2y ago
why would that matter?
Bugz000
Bugz000OPā€¢2y ago
well i need to run the compiler no?
ero
eroā€¢2y ago
dotnet run it's added to your PATH, you don't need to look for it
Bugz000
Bugz000OPā€¢2y ago
i pointed it to the cs file but it wants a whole project structure oh i should read what it says that helps
ero
eroā€¢2y ago
you don't even need to specify the project you just need to execute dotnet run in the project directory
Bugz000
Bugz000OPā€¢2y ago
(1,1): error MSB4025: The proje
ct file could not be loaded. Data at the root level is invalid. Line
1, position 1.

The build failed. Fix the build errors and run again.
(1,1): error MSB4025: The proje
ct file could not be loaded. Data at the root level is invalid. Line
1, position 1.

The build failed. Fix the build errors and run again.
doesn't want to run in the directory either
ero
eroā€¢2y ago
you did dotnet new console?
Bugz000
Bugz000OPā€¢2y ago
i did not, it's made a csproj file
ero
eroā€¢2y ago
do you figure perhaps that's the issue
Bugz000
Bugz000OPā€¢2y ago
lol yes it's upset with a few things hold on
error CS0101: The nam espace '<global namespace>' already contains a definition for 'TUI'
ero
eroā€¢2y ago
you must have 2 type declarations with the same name
Bugz000
Bugz000OPā€¢2y ago
i don't see how though
ero
eroā€¢2y ago
neither do i i don't see anything since you're not sharing anything
Bugz000
Bugz000OPā€¢2y ago
ya hold on i aint so fast
using System;
using System.Collections;
using System.Collections.Generic;

TUI tui = new();
tui.Main();

class TUI
{
private void Append(string input)
{
Type type = typeof(ConsoleColor);
Dictionary<int, string> ConsoleColors = new Dictionary<int, string>();
var loopCounter = 0;
foreach (var name in Enum.GetNames(type))
{
loopCounter++;
ConsoleColors[loopCounter] = name;
}
foreach (char chr in input)
{
if (((int)chr) <= 15)
{
Console.ForegroundColor = (ConsoleColor)Enum.Parse(type, ConsoleColors[(int)chr]);
continue;
}
Console.Write(chr);
}
Console.Write("\n");
}
private int rand(int low, int high)
{
Random rnd = new Random();
int output = rnd.Next(low, high);
return output;
}
private char Chr(int input)
{
char ret = Convert.ToChar(input);
return ret;
}
private void intro()
{
int col = rand(2,15);
int col2 = rand(2,15);
int col3 = rand(2,15);
}
public void Main()
{
intro();
}
}
using System;
using System.Collections;
using System.Collections.Generic;

TUI tui = new();
tui.Main();

class TUI
{
private void Append(string input)
{
Type type = typeof(ConsoleColor);
Dictionary<int, string> ConsoleColors = new Dictionary<int, string>();
var loopCounter = 0;
foreach (var name in Enum.GetNames(type))
{
loopCounter++;
ConsoleColors[loopCounter] = name;
}
foreach (char chr in input)
{
if (((int)chr) <= 15)
{
Console.ForegroundColor = (ConsoleColor)Enum.Parse(type, ConsoleColors[(int)chr]);
continue;
}
Console.Write(chr);
}
Console.Write("\n");
}
private int rand(int low, int high)
{
Random rnd = new Random();
int output = rnd.Next(low, high);
return output;
}
private char Chr(int input)
{
char ret = Convert.ToChar(input);
return ret;
}
private void intro()
{
int col = rand(2,15);
int col2 = rand(2,15);
int col3 = rand(2,15);
}
public void Main()
{
intro();
}
}
i didn't leave a static anywhere so it should be invoked with TUI tui = new();
ero
eroā€¢2y ago
i don't know what your project makeup is at this point
Bugz000
Bugz000OPā€¢2y ago
that is it entirely
ero
eroā€¢2y ago
no, you must have a csproj file this cannot be all of your files
Bugz000
Bugz000OPā€¢2y ago
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>compress_images</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>compress_images</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
and i moved the code to "program.cs" which it made oh heck it was picking up the old cs file aswell the exe it made doesn't hook the existing console instance
ero
eroā€¢2y ago
and why would it that doesn't even make sense it's its own program
Bugz000
Bugz000OPā€¢2y ago
thats how the old compiler works and how i'd expect it to
ero
eroā€¢2y ago
it's not gonna hook to anything you built an entirely new executable you're not running it in some compiler
Bugz000
Bugz000OPā€¢2y ago
correct
ero
eroā€¢2y ago
dotnet run is gonna run in your console just... execute it in an open console
Bugz000
Bugz000OPā€¢2y ago
and when i run the exe from console it should
ero
eroā€¢2y ago
ero
eroā€¢2y ago
works fine
Bugz000
Bugz000OPā€¢2y ago
ya that's what i'm trying but it flashes up a new console window for a few milliseconds which tells me it's making a new terminal, running, and closing, it should hook the existing terminal which called it and end back at the command line prompt no?
ero
eroā€¢2y ago
no, it should not that does not make sense
Bugz000
Bugz000OPā€¢2y ago
thats how the old one worked :\
ero
eroā€¢2y ago
when you start discord, it doesn't open in an existing console either, does it so why should this it's a completely separate executable you could send this executable to anyone, and as long as they have the runtime installed, they could run it
Bugz000
Bugz000OPā€¢2y ago
https://cqdx.uk/i/mgdM.mp4 you see the difference
ero
eroā€¢2y ago
one seems to be functional code, the other seems not to be actually, no the code you sent here literally does nothing so that's just expected there is no output no nothing so obviously it's not going to display anything
Bugz000
Bugz000OPā€¢2y ago
hold on sorry fun discord wont let me send it but https://cqdx.uk/i/8WOK.txt ammended code with output (but still broken) reverted to last "working" to get this compiler running oh wait hold on
Bugz000
Bugz000OPā€¢2y ago
ero
eroā€¢2y ago
ero
eroā€¢2y ago
?
Bugz000
Bugz000OPā€¢2y ago
well now the rand is updating šŸ¤” you see that right
ero
eroā€¢2y ago
no, i don't know what your code does
Bugz000
Bugz000OPā€¢2y ago
Bugz000
Bugz000OPā€¢2y ago
top, solid block color, rand was returning the same each time bottom, it is not to be clear, bottom is intended functionality but i'm curious what changed besides a newer compiler, because that's some core functionality that's different UwU? šŸ‘‰ šŸ‘ˆ
ero
eroā€¢2y ago
i don't know but you can use Random.Shared there anyway it's a globally shared instance of Random don't need to allocate a new one each call
static int rand(int low, int high)
{
int output = Random.Shared.Next(low, high);
return output;
}
static int rand(int low, int high)
{
int output = Random.Shared.Next(low, high);
return output;
}
Bugz000
Bugz000OPā€¢2y ago
that requires no invoking? it is implicit it IS implicit neat
ero
eroā€¢2y ago
and honestly, therefore, that function is kinda pointless you can just do int col = Random.Shared.Next(2, 15);
Bugz000
Bugz000OPā€¢2y ago
yup haha a lot of this is boilerplate as i'm moving a big project to C# porting languages so a lot of this is "mimicing" the functions i made in the other language required there, not so much here, but for ease of moving i'll do it
ero
eroā€¢2y ago
fair enough
Bugz000
Bugz000OPā€¢2y ago
well it APPEARS to be working, and it hooks the instance too as before and rand magically works through voodoo means although i'm still relying on static here
ero
eroā€¢2y ago
could very well be that they changed the internal implementation of Random so perhaps the time seed intervals are smaller or other stuff which is why you wanna be up to date on .net versions, better features your class here doesn't use any instance data so making everything static is fine
Bugz000
Bugz000OPā€¢2y ago
that is a valid structure? have a main class that self invokes and go from there
ero
eroā€¢2y ago
sure you'd normally use top level statements here, and just have classes for the different steps
Bugz000
Bugz000OPā€¢2y ago
i started like this as it's what i recall from C++ classes but that was nearly 20 years ago
ero
eroā€¢2y ago
like for example, i would call this Logo or something, and have the method that actually does the showing be named Show or something
Bugz000
Bugz000OPā€¢2y ago
classes in the academic sense* mmm well a lot of my console stuff in my other language
Bugz000
Bugz000OPā€¢2y ago
Bugz000
Bugz000OPā€¢2y ago
one is running right here infact lol uses a markup chr(1) to chr(15) to denote what color to set for that part makes setting the color inline much easier the append func detects these and substitutes them for whatever "color change" may be, different per language ofc and that's pretty much as far as i got so this class is more of a terminal "wrapper" of sorts which i like to include in all my programs Autohotkey is not an ideal language for hamming distance though so it's about time i shifted to something more capable yes you can laugh, ahk is easy to use though šŸ˜† hey i got top layer things working too
Terminal thing = new();
thing.Main();
Terminal thing = new();
thing.Main();
Bugz000
Bugz000OPā€¢2y ago
ero
eroā€¢2y ago
class Logo
{
private static ConsoleColor[] _consoleColors = Enum.GetValues<ConsoleColor>();

public static void Show()
{
char c1 = (char)Random.Shared.Next(2, 16);
char c2 = (char)Random.Shared.Next(2, 16);
char c3 = (char)Random.Shared.Next(2, 16);

WriteColoredLine($"{c2} ) ) ) ) ");
WriteColoredLine($"{c2} ( {c2}/({c3} ( ( ( ( {c2}/( {c3}( {c2}/( {c3}( {c2}/( ");
WriteColoredLine($"{c3} )\\{c2}_){c3}) ){c2})\\ )\\)){c3}( ( )\\{c2}_){c3}))\\{c2}_){c3}))\\{c2}_){c3}) ");
WriteColoredLine($"{c3} ((_)\\ /((_|(_))\\ )\\ ((_)\\((_)\\((_)\\ ");
WriteColoredLine($"{(char)12} | |{c3}(_|_))( (()(_|(_){(char)8}_/---\\/---\\/---\\ ");
WriteColoredLine($"{(char)11} | '_ \\ || / __ ||_ / /\\ | /\\ | /\\ | ");
WriteColoredLine($"{(char)10} | |_|| || | || | / /_ \\/ | \\/ | \\/ | ");
WriteColoredLine($"{(char)10} |_.__/\\_,_\\__, |/___|\\__/ \\__/ \\__/ ");
WriteColoredLine($"{(char)10} |___/ ");
}

private static void WriteColoredLine(object? output)
{
if (output is null)
{
Console.WriteLine();
return;
}

string sOutput = output.ToString()!;

foreach (char c in sOutput)
{
if (c <= _consoleColors.Length)
{
Console.ForegroundColor = _consoleColors[c - 1];
}
else
{
Console.Write(c);
}
}

Console.WriteLine();
}
}
class Logo
{
private static ConsoleColor[] _consoleColors = Enum.GetValues<ConsoleColor>();

public static void Show()
{
char c1 = (char)Random.Shared.Next(2, 16);
char c2 = (char)Random.Shared.Next(2, 16);
char c3 = (char)Random.Shared.Next(2, 16);

WriteColoredLine($"{c2} ) ) ) ) ");
WriteColoredLine($"{c2} ( {c2}/({c3} ( ( ( ( {c2}/( {c3}( {c2}/( {c3}( {c2}/( ");
WriteColoredLine($"{c3} )\\{c2}_){c3}) ){c2})\\ )\\)){c3}( ( )\\{c2}_){c3}))\\{c2}_){c3}))\\{c2}_){c3}) ");
WriteColoredLine($"{c3} ((_)\\ /((_|(_))\\ )\\ ((_)\\((_)\\((_)\\ ");
WriteColoredLine($"{(char)12} | |{c3}(_|_))( (()(_|(_){(char)8}_/---\\/---\\/---\\ ");
WriteColoredLine($"{(char)11} | '_ \\ || / __ ||_ / /\\ | /\\ | /\\ | ");
WriteColoredLine($"{(char)10} | |_|| || | || | / /_ \\/ | \\/ | \\/ | ");
WriteColoredLine($"{(char)10} |_.__/\\_,_\\__, |/___|\\__/ \\__/ \\__/ ");
WriteColoredLine($"{(char)10} |___/ ");
}

private static void WriteColoredLine(object? output)
{
if (output is null)
{
Console.WriteLine();
return;
}

string sOutput = output.ToString()!;

foreach (char c in sOutput)
{
if (c <= _consoleColors.Length)
{
Console.ForegroundColor = _consoleColors[c - 1];
}
else
{
Console.Write(c);
}
}

Console.WriteLine();
}
}
i'd probably do something like this keep in mind that Random.Next's max value is exclusive so you need 2, 16 if you want it to be able to generate 15
Bugz000
Bugz000OPā€¢2y ago
aha good call {c2} is your own markup?
ero
eroā€¢2y ago
no that's an interpolated string $interpolation
MODiX
MODiXā€¢2y ago
String interpolation is the preferred way of building strings in C#. It is easier to read than concatenation. For example:
var foo = 1;
var bar = 2;
Console.WriteLine("foo is equal to: " + foo + " and bar is equal to: " + bar);
var foo = 1;
var bar = 2;
Console.WriteLine("foo is equal to: " + foo + " and bar is equal to: " + bar);
can be written as:
var foo = 1;
var bar = 2;
Console.WriteLine($"foo is equal to: {foo} and bar is equal to: {bar}");
var foo = 1;
var bar = 2;
Console.WriteLine($"foo is equal to: {foo} and bar is equal to: {bar}");
Bugz000
Bugz000OPā€¢2y ago
OH FK its expression mode thats so much easier
ero
eroā€¢2y ago
(also you never use c1/col in your code)
Bugz000
Bugz000OPā€¢2y ago
ya c1/col is a big block of nonsense i omitted from testing its just big ascii art i put in all my consoles it's not important for this or rather it's the color for it *
private static ConsoleColor[] _consoleColors = Enum.GetValues<ConsoleColor>();
private static ConsoleColor[] _consoleColors = Enum.GetValues<ConsoleColor>();
i re-make the whole consolecolors array each time i run a line aswell this is much better
ero
eroā€¢2y ago
you also did loopCounter++ before adding the thing to the dictionary, so the keys start at 1 instead of 0 which is why i had to do _consoleColors[c - 1]
Bugz000
Bugz000OPā€¢2y ago
yes thats because AHK starts at 1 so all my colors are from 1 it was intentional but honestly i could do with updating the color markup a bit given all the colors are in different places
static Colors := {"Black":0,"Navy":1,"Green":2,"Teal":3,"Maroon":4,"Purple":5,"Olive":6
,"Silver":7,"Gray":8,"Blue":9,"Lime":10,"Aqua":11,"Red":12,"Fuchsia":13,"Yellow":14,"White":15}
static Colors := {"Black":0,"Navy":1,"Green":2,"Teal":3,"Maroon":4,"Purple":5,"Olive":6
,"Silver":7,"Gray":8,"Blue":9,"Lime":10,"Aqua":11,"Red":12,"Fuchsia":13,"Yellow":14,"White":15}
guess they do start at 0 but nobody uses black sorry that's an assoc array so colors[1] or colors["black"] would return 0, typeless coding you can do some cursed stuff double deref is another fun thing lol
milk:="a"
b%milk%con:="tomato"
MsgBox, Did you know that this is valid code?
??? It's amazing how you can abuse AHK when you know...
... how it works...
:) Really, there's a lot you can do with it that you wouldn't think.
. %bacon%
milk:="a"
b%milk%con:="tomato"
MsgBox, Did you know that this is valid code?
??? It's amazing how you can abuse AHK when you know...
... how it works...
:) Really, there's a lot you can do with it that you wouldn't think.
. %bacon%
Bugz000
Bugz000OPā€¢2y ago
Bugz000
Bugz000OPā€¢2y ago
some fun
ero
eroā€¢2y ago
ugh
Bugz000
Bugz000OPā€¢2y ago
ahhaha it shouldn't exist but it does you have
(char)12
(char)12
instead of c12 did you miss it no it works nevermind ignore that
Bugz000
Bugz000OPā€¢2y ago
Bugz000
Bugz000OPā€¢2y ago
the colors are random it just landed the same by chance lol those shouldnt' actually be random oddly enough - but it is all working šŸ˜„ thankyou ā¤ļø
Bugz000
Bugz000OPā€¢2y ago
https://www.youtube.com/watch?v=fjWmSeoLOxc this is the terminal system i'm recreating either way, then i'll port my code to the new platform
Bugz000
Bugz000OPā€¢2y ago
thankies for your help ā¤ļø i will no doubt be back at some point with some other silly issue :p but for now i bid you gratitude and farewell
Accord
Accordā€¢2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server