Gamelog not working
I had to create a game trough a mvc controller and the gamelog isnt logging my details
67 Replies
$details
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
it should look like this
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/
this is my details view
is there something wrong here that is making it not show the details
are you sure there is any data being passed to the view?
set a breakpoint in the controller action before you invoke the view
where is this sorry if im asking a dumb question
i had to create a database which i did
then trough nuggets create the tables and that also worked now showing me the screen at the top
if u also need this info just incase
so in MVC you have three components
Model, View, Controller
I want you to go into the controller and show us the code
oh alright ill send it right now
its saying
the code is to long to send in here
too many characters
MODiX#0152
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/Quoted by
<@105026391237480448> from #Gamelog not working (click here)
React with ❌ to remove this embed.
do i send u the link now?
yes.
file:///C:/Users/erena/Downloads/BlazeBin.html
BlazeBin
A tool for sharing your source code with the world!
does this work?
BlazeBin - iuvcnetsxggi
A tool for sharing your source code with the world!
idk which link is correct here
The last one.
And uh... how is that not obvious? I genuinely ask.
oh okay
so u see what the issue is or as in the break point position u mentioned
The first is the path to a file on your computer.
the second is just "paste.mod.gg"
the third one has some form of unique ID in it
yh just asking to make sure
my bad
I think thats the wrong controller?
i also have created another controller for the gamelogs
let me send this in too maybe thats what is needed here to look at
Look.
You paste an image of the GameLogs view empty
and you send me the code for an unrelated controller
Come on!
sorry
BlazeBin - jqqoddmzeinb
A tool for sharing your source code with the world!
this is the other controller that is related to gamelogs
okay so what we are looking at is
thats the action that calls the view you showed
yeah
lets separate that into two calls, so we can inspect the variable
var gamelogs = await _context...
then return View(gamelogs);
okay so i will change that real quick
so u have the gamelogs awaiting context
then the view returns the gamelogs
its the exact same code as you already have
just broken up into two lines
yeah just seperated
ye
and then I want you to set a breakpoint on the second line, the
return
oneokay ill change it to that real quick and set the breakpoint
done
okay, and the breakpoint is set?
yes but when i click f11 it doesnt bring me to it
thats... uh... what
start the program, open your gamelogs page
that should hit the breakpoint
it did yes
this is what its showing rn
sorry if screenshots are annoying
count = 0
your database contains no game log entries
so its counting nothing indeed
so yeah, no data is showing
because you have no data
right and retrieving data will be done how exactly
what do you mean?
because we need to type in a specific location which is the url
and then it will say hit miss or invalid location
which should be the log of the game
so you're making the game Battleships?
seabattle yeah
await _context.GameLogs.ToListAsync();
this is the code that fetches all your logs from the database
all of them
but your database currently doesnt contain anyright
so do i need to add it
because it should just retrieve the data
when a player does something
but its not
uh
are you mixing up the word "retrieve" and "add"?
retrieve is to fetch something
you already do that
let me show u what i mean
cuz im wording it wrong
Go ahead, but I'm gonna go to bed.
so this is the result
then it should log that it was a miss for example
oh alr goodnight
your code for
ThrowBomb
doesnt add anything to the logs database
in fact, it doesnt write anything to anywhere
it just updates the ViewBag 3 times.
Please don't use the viewbag 😦i have no idea else how to do it
so what do i need to adjust for it to do that then
Add something to the database?
do i need to do that trough sql?
because in the project they dont tell us to ever do that
hence why im confused why its not working
maybe another nugget command
well, you can't get something from the database that you didn't put in
_context.GameLogs.Add(...)
and then await _context.SaveChangesAsync();
but you need to figure out what to add and whereexactly my point
but i dont understand why they never mention putting something in
yeah
is that missing in my code?
.. yes?
I don't really understand how that isn't obvious
Your code has no mention of adding to the database at all - and you are wondering if that's why your database is empty?