C
C#SirRodgerBottoms

❔ need some help for school assignment - changing image via variable

hey, having problems building a microsoft form in c#, part of my assignment is to build a basic educational game, in order to make it slightly more friendly to children my group decided to add an option to pick a profile image just as an additional thing to keep kids from being completely bored to death. I have tried a few different methods and cannot get the image to change unless its an event on clicking the initial selection of images (image 1), this also assigns a variable "intProfile" a number and i was hoping that on form2 loading i could use an if statement to change a picture box in the corner. its refusing to work, any help would be greatly appreciated
A
Angius384d ago
= is for assignment == is for comparison And it also gives you a bool, no need to convert anything
S
SirRodgerBottoms384d ago
i was being forced to convert to bool, but will test the == to see if that works
J
Jimmacle384d ago
globalvar pepesus
S
SirRodgerBottoms384d ago
goddamn that worked, thank you lol so i can carry the selection over from form to form
A
Angius384d ago
If it didn't work, it'd mean C# itself is broken
J
Jimmacle384d ago
there is almost definitely a better way to pass data between objects than a bunch of global variables, but would need more context
S
SirRodgerBottoms384d ago
i was having so many troubles last night getting it to work without it being on click so i figured it would work doing it on load on the next form, just forgot the double == lol
J
Jimmacle384d ago
also, you don't need Convert and it's not really used anymore
S
SirRodgerBottoms384d ago
i imagine so but for this class thats how we have been taught and i think they expect to see variables done that way for now i was getting errors without it
J
Jimmacle384d ago
any object has a ToString() method defined on it, and to go the other way they have static parsing methods defined
A
Angius384d ago
Ah, a school project Well, bad practices are to be expected
J
Jimmacle384d ago
that was my favorite part about school being forced to write shitty code because that's how the professors wanted it
S
SirRodgerBottoms384d ago
yeah going back to school later in life after learning redundant things on byond and gamemaker lol yeah lol, but to be fair the project itself is boring, and this is only for the menu, im just making a simple spelling game, kid clicks audio button, word plays out loud, type it in box correctly just out of interest tho, how would you suggest doing the variables instead of creating a seperate class?
J
Jimmacle384d ago
normally you'd pass data around with method arguments and returns, there's almost never a good reason to have a global state the way you have it now
S
SirRodgerBottoms384d ago
any decent websites with examples i could look at?
J
Jimmacle384d ago
something should "own" the data and control what happens to it
A
Angius384d ago
Most proper would be using dependency injection and registering some UserService singleton that stores the data about the user
J
Jimmacle384d ago
i wasn't going to drown him in figuring out DI just yet LUL
S
SirRodgerBottoms384d ago
would creating the variable on the form itself not mean they are bound to that form itself though?
J
Jimmacle384d ago
it would be bound to that instance of the form, yes
S
SirRodgerBottoms384d ago
would that be similar to just having a page of code that is called upon specifically for the variables? cause i know i used to do that sorta thing on byond although it just did most of the backend work for me
A
Angius384d ago
No idea what "byond" is, or what do you refer to as a "page of code". But, in short, dependency injection means you create a class and register it in the DI container. Then, any class also registered in that container, can request an instance of it. In case of a singleton, that instance is shared So you can request UserService class in two different places, do _userService.Foo = 69; in one place, and getting _userService.Foo; would return 69 in the other
S
SirRodgerBottoms384d ago
ohh ok, yeah i made a class for the "user data" (basically first name second name and profile pic selection) was going to make a seperate class for the actual game stuff it does seem that im maybe not understanding it just yet but regardless my issue is sorted lol, thank you guys for the help also byond is a 2.5d game engine that uses its own bastardised version of i think objective C, allows users to create mmo games, most ingame commands are referred to as verbs
A
Angius384d ago
Gotcha, TIL
S
SirRodgerBottoms384d ago
used to be pretty popular, think its still around but they banned any fanmade games from other franchises lol
A
Accord375d 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
More Posts
❔ Writing to StreamWriter FailsHi, I was experimenting with permanently saving things for the first time and ran into problems. Des❔ road mapi have a question, basic c# and .which topic should I study after netcore 5 training?✅ Testing GitHub webhooks on my local machineI'm currently developing a project using <https://github.com/octokit/webhooks.net>. What's the best ❔ How to prevent code from being leaked?When you created a tool and added a licence system like auth.gg, how can you make the code unreadabl❔ Http postHello guys My issue is when I click submit I get This page isn’t working right now If the problem co✅ How to get the form style of a processI need to get the form style of a process❔ Can i develop a discord music bot or admin bot using C#?If i can, how? Any idea?❔ Console inputHi, is it possible to enable console input in web sdk using Host? ```csharp public static as❔ MediaPlayer in WPF occasionally fails```cs public static void PlaySound(string path) { Task.Run(() => ❔ How to Create a C# Code Base for a PC CleanerDoes anyone know of C# to make a base code that for now just clean the %temp% folder just for me to ✅ How to install a callback for an awaited item when using Task.WhenAllHello I am using Task.WhenAll on a List of Tasks. However if a task fails I want to immediately call❔ How to get azure cache for Redis connection string stored in app service as a appsetting variableI have created a azure redis for cache and stored the connection string as application setting varia❔ Giveaway for an online DOTNET ConferenceHello developer students, I am going to give away free tickets to an online dotnet conference whic❔ SoundBoardHi! I am working on a soundboard lately and i got stuck with playing a sound throught microphone. i'❔ accessing object from a class inside of another classI got this class called "Engine"(image 1) that has the object "isOn" which indicates whether the eng❔ QuestionControllerHello, i have a question regarding API structure. I have two classses, Item and Store. I created C❔ Problem Binding to Image SizeI am making an app that displays a series of books. An image and title of the book is to be displaye❔ whats the best site or youtube channel to start learning c#?just downloaded visual studio and wanted to know what would be the best way to learn C#❔ C# MVC - Erroring in VSC not VS2022I'm writing a C# .Net Core 7.0 web application with dapper for my SQL queries. It runs just fine inString Contain issueSo im trying to get a word in a string using Contain but its not getting the word, I havent found a