C
C#10mo ago
Mekasu0124

❔ ✅ get unknown range of list to display?

internal record Evidence(string Name)
{
public static Evidence None = new Evidence("None");
public static Evidence Emf5 = new Evidence("EMF 5");
public static Evidence SpiritBox = new Evidence("Spirit Box");
public static Evidence Writing = new Evidence("Ghost Writing");
public static Evidence Dots = new Evidence("DOTs Projector");
public static Evidence Ultraviolet = new Evidence("Ultraviolet");
public static Evidence Freezing = new Evidence("Freezing Temperatures");
public static Evidence GhostOrbs = new Evidence("Ghost Orbs");

public override string ToString() => Name;
}
internal record Evidence(string Name)
{
public static Evidence None = new Evidence("None");
public static Evidence Emf5 = new Evidence("EMF 5");
public static Evidence SpiritBox = new Evidence("Spirit Box");
public static Evidence Writing = new Evidence("Ghost Writing");
public static Evidence Dots = new Evidence("DOTs Projector");
public static Evidence Ultraviolet = new Evidence("Ultraviolet");
public static Evidence Freezing = new Evidence("Freezing Temperatures");
public static Evidence GhostOrbs = new Evidence("Ghost Orbs");

public override string ToString() => Name;
}
this information is generated into a string like string evidence = "EMF 5, Spirit Box, Ghost Writing";. Knowing that it's not the same evidence every time, how can I cut off the last piece of evidence and display the first two?
33 Replies
Pobiega
Pobiega10mo ago
split the string on , and drop the last item?
Mekasu0124
Mekasu012410mo ago
string evidenceZero = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence).Split(", ")[0];
string evidenceOne = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence).Split(", ")[1];
string evidnce = evidenceZero + evidenceOne;
string evidenceZero = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence).Split(", ")[0];
string evidenceOne = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence).Split(", ")[1];
string evidnce = evidenceZero + evidenceOne;
like this?
Pobiega
Pobiega10mo ago
ugh, no
Mekasu0124
Mekasu012410mo ago
well this is how it's generated into a string....
Pobiega
Pobiega10mo ago
well if you already have it as an array, isnt it better to just use the array then? why convert to string, remove the last item, then convert back into array, to then convert to string again? that seems insanely convoluted 😄
Mekasu0124
Mekasu012410mo ago
idk that's why I asked. This isn't python so it's confusing.....sorry. I don't mean to disappoint
Pobiega
Pobiega10mo ago
so, this is an X Y problem you're trying to solve X, your attempted solution is Y, so you're asking about Y I need you to tell me about X what is the actual problem you are trying to solve here?
Mekasu0124
Mekasu012410mo ago
ok you said it's already an array
Pobiega
Pobiega10mo ago
ghost.Evidence is, last time we talked so if you have access to that, its much easier to work with that directly
Mekasu0124
Mekasu012410mo ago
string evidenceZero = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence[0]);
string evidenceOne = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence[1]);
string evidence = evidenceZero + evidenceOne;
string evidenceZero = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence[0]);
string evidenceOne = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence[1]);
string evidence = evidenceZero + evidenceOne;
so I should be able to do something like this then, right?
Pobiega
Pobiega10mo ago
rather than the string version uhm.. what do you think string.Join does?
Mekasu0124
Mekasu012410mo ago
joins an array to a string that's why I'm trying to index the array
Pobiega
Pobiega10mo ago
right. and ghost.Evidence is an array, that we agree on what is ghost.Evidence[0] thou? is that also an array?
Mekasu0124
Mekasu012410mo ago
internal class Ghost
{
public required string Name { get; init; }
public required string NormalizedName { get; set; }
public required string Description { get; set; }
public required string Weakness { get; set; }
public required string Strength { get; set; }
public required Evidence[] Evidence { get; set; }
public required HuntSanity Sanity { get; set; }
public required Speed Speed { get; set; }
public required Tell[] Tells { get; set; }
public required Behavior[] Behaviors { get; set; }
public required HuntSanityBehavior[] HuntSanityBehaviors { get; set; }
public required HuntSpeedBehavior[] HuntSpeedBehaviors { get; set; }
public required Evidence[] GuaranteedEvidence { get; set; }
}
internal class Ghost
{
public required string Name { get; init; }
public required string NormalizedName { get; set; }
public required string Description { get; set; }
public required string Weakness { get; set; }
public required string Strength { get; set; }
public required Evidence[] Evidence { get; set; }
public required HuntSanity Sanity { get; set; }
public required Speed Speed { get; set; }
public required Tell[] Tells { get; set; }
public required Behavior[] Behaviors { get; set; }
public required HuntSanityBehavior[] HuntSanityBehaviors { get; set; }
public required HuntSpeedBehavior[] HuntSpeedBehaviors { get; set; }
public required Evidence[] GuaranteedEvidence { get; set; }
}
in the ghost model, it is done as an array.
"Evidence": [
{
"Name": "EMF 5"
},
{
"Name": "Spirit Box"
},
{
"Name": "Ghost Writing"
}
],
"Evidence": [
{
"Name": "EMF 5"
},
{
"Name": "Spirit Box"
},
{
"Name": "Ghost Writing"
}
],
then it's stored to the json file like so. When I pull it from the json file,
string evidenceZero = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence))
string evidenceZero = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence))
I do so like this to get it into a string that looks like "EMF 5, Spirit Box, Ghost Writing" so it's easier to print to the screen. I'm just trying to figure out how to drop the last item in the string
Pobiega
Pobiega10mo ago
but why in the string? isnt the string literally just a display interpretation of the array? you shouldn't be modifying the string, you should be modifying the array and honestly, at that point, it shouldn't be an array, it should be a list you're still focused on Y tell me about X. why do you want to drop the last item from the string?
Mekasu0124
Mekasu012410mo ago
because it's part of the game?
Pobiega
Pobiega10mo ago
explain
Mekasu0124
Mekasu012410mo ago
for what? It's part of the game. I just need to know the most efficient way to drop the last item from that string, or from the array.....
Pobiega
Pobiega10mo ago
What i've gathered about your project so far is that its a guessing game right you get some info on a ghost and you're supposed to identify it
SinFluxx
SinFluxx10mo ago
I'm assuming Phasmophobia or similar? You go around the map and discover certain pieces of evidence then mark them in your notebook as discovered evidence to identify what type of ghost it is
Mekasu0124
Mekasu012410mo ago
it's just part of the games difficulty level.
Pobiega
Pobiega10mo ago
there we go THATS what X is
Mekasu0124
Mekasu012410mo ago
I don't understand why the reason I'm wanting to drop the last item in the list is relevant to learning how to do it
Pobiega
Pobiega10mo ago
you want a way to "hide" evidence from the player to increase difficulty
Mekasu0124
Mekasu012410mo ago
it's just dropping one item from teh list
Pobiega
Pobiega10mo ago
Look, I either help you my way, or I don't help you. Pick one.
Mekasu0124
Mekasu012410mo ago
me not wanting to release details about my game that I'm developing that I haven't told anyone about at all has nothing to do with receiving assistance in learning how to drop an item from a list. But alright, your pride. your way. thanks for the help
Pobiega
Pobiega10mo ago
$xy
MODiX
MODiX10mo ago
The XY Problem
Asking about your attempted solution rather than your actual problem
Pobiega
Pobiega10mo ago
read this, and perhaps you'll understand if not, best of luck with your your programs
Pobiega
Pobiega10mo ago
Mekasu0124
Mekasu012410mo ago
yea I'm good. I figured it out by myself
Accord
Accord10mo 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.