Problem with inventory replication on Unreal Engine 4 - replication

I made an inventory system on UE4, but to do the inventory itself I created a component which represent the inventory of the player and the inventory of lootable vehicles.
The problem is that when I take a stuff in the vehicle's inventory, I delete it from the inventory and create a slot in the player inventory to store the item. But the slot refresh is made in the HUD so I don't know how to replicate it. Should I recode this whole part in the BP_character rather than the in HUD?

I'm not some professional and I'm having issues of my own with the same area you're working on, but what I think you do want your inventory as a component on your character (with an array and inventory logic stuff in the component blueprint). Then, whenever the player opens their appropriate HUD to view their inventory, it loads the HUD according to what's in the inventory component's array. All changes to the array should be done explicitly by the server (by making sure it's replicated and doing authority checks anywhere you make updates to the array.

You're on the right track as the HUD is not the place to keep your inventory. The character is a better place but the best place to keep it is in the GameInstance.
The GameInstance is a persistent class that is always available from anywhere in the game. This makes it very useful for many things besides your inventory.
Keeping the inventory here means you can use code anywhere you like to move items to or from the player's inventory. E.g. if an NPC wants to give an item to the player, you can do that with code on the NPC class, because the NPC class can see the player's inventory.
Likewise, if the inventory is on the GameInstance, the HUD can also see it.

Related

Can you activate a method on an Area2D node with the player's raycast2D in Godot?

I created a sort of old style jrpg movement system with a 3 character party. The first character (the player) uses a raycast for checking of surrounding tiles and movement.
I want the player to come close to a shop tile and hit a button to open a dialog.
Player is in the middle, shop is above him, like so:
How would I activate a custom function on the shop tile?
I tried using raycasts and signals. The shop is an Area2D tile.
Is it even possible to trigger an Area2D on_entered signal with a raycast?
The default signals seem to be incorrect for this use, but so do custom signals.
There is probably something very simple I'am missing.
Thanks for any help.
You could check what the raycast is colliding with. Since it looks like you are placing an Area2D on top of a TileMap, why not make the shop a StaticBody2D instead of a tile, and attach the shop script. It would be typical for game objects other than the walls to not be in the TileMap.
Somewhere with your player's movement code:
if Input.is_action_just_pressed("interact"):
var collider = raycast.get_collider()
if collider != null:
if collider.has_method("open_shop"):
collider.call_deferred("open_shop")
I am assuming here that the raycast is properly updated already in your movement code, either by the raycast property enabled being true, or having a call to force_raycast_update().
Here, raycast should be replaced with any reference to the player's Raycast2D, and "open_shop" should be replaced with the function name (still as a string literal) from the shop script you wanted to call.

Getting Contact Information with Tiles in Godot

Can I somehow get information that the player has touched a specific tile located in the resource (tilemap.res)?
It is necessary to determine which tile it stands on (for example, on land or in water)
It depends on what kind of behavior you're expecting. There's two major ways to do this:
In each individual script that you want to be affected by the tiles, get the tile it's on every time it moves, then run the logic directly from there.
As above, get the tile the unit is on each time it moves, but instead of just running the logic every time, emit a signal whenever the tile changes, and keep the current tile cached so you can check when it's on a new tile; have the TileMap itself attach to the signal, and when it receives the signal, act on the Node2D until it leaves. This is what I'd do.
The exact method to find the tile is TileMap.world_to_map(TileMap.get_cellv(Node2D.position))--you just need to have the Node2D and the TileMap, and you can get both in the same function using the above two methods.
Technically, you could also procedurally add Area2Ds to the tilemap based on the tiles at various positions using TileMap.get_used_cells_by_id, making sure that the ID is the one that has the special behavior, then attaching the TileMap to those areas' body/area_entered and body/area_exited and using that, but spamming a whole lot of Area2Ds isn't necessary when you can check the tile a Node2D is on directly.

NSTableView infinite scroll or pagination

In relation to How to determine if a user has scrolled to the end of an NSTableView
Thanks Josh.
Is there a way to use this mechanism to implement a NSTableView that provides some sort of infinite scroll or pagination.
The idea is to tell NSTableView to load up to a certain number of records, say 1k records at once and than as user scrolls closer to the end pull another 1k records and maybe forget the first 1k records.
This pattern is well defined/used in web applications and java. Only the visible number of rows is loaded initially and the rest is pulled async as user scrolls up and down the table.
I am interested in some obj-c code or tips on how to code this.
I know about filtering/limiting the number of records that go into the tableview but lets ignore that for a moment.
Thanks.
Given the details you've provided, I'll generalize a bit but here's how I might solve it:
First, I'd set a MUCH SMALLER batch size than 1000 records. If the result count or "the most anybody is ever going to want to see" is indeterminate (and it sounds like it is in your case), the user probably doesn't even care past the first 100 or so. If your user often requests a large, expensive list and immediately wants to see stuff so far away from the beginning they hurl the scroller downward for two minutes straight before they stop and look around, perhaps a more intuitive sort order is needed instead of asking Google Image for 1000 more animated kitten gifs. ;-)
The controller behind the (definitely view-based for view reuse) table view will need some sort of request queue since I assume you're batching things in because they're expensive to retrieve individually. This will manage the asynchronous requesting/okay-now-it's-loaded machinery (I know that's vague but more detail is needed to get more specific). You'll make sure any "currently alive" views will somehow get this "it's ready" notification and will go from some "busy" UI state to displaying the ready item (since we NEVER want to keep the table waiting for a ready-to-display view for the object at a given row, so the view should at least show some "still waiting for details" indication so quick scrolls over lots of rows won't stall anything).
Using a view-based NSTableView and associated data source methods will let the table view handle only keeping enough copies of your custom NSTableCellView around to reuse during scrolling. Since you have to provide a configured view when asked, the view's default state can either be "draw nothing if not ready" or some visually generic placeholder until the object is realized and ready (then you can just reload that row instead of the whole table). This way the table keeps scrolling and drawing rapidly because it doesn't care about what your controller is doing to fulfill the promise of updating the visible rows (that custom cell view of yours will observe its represented object's updates).
You probably want the scrollers to reflect the total number of rows batched in so far if the upper bound is astronomical - reflecting that size would make the scroll grip both tiny and very sensitive. Instead, just grow the scroller (via the table view's row count) by what the user has "requested" so far, all the way back to the beginning of the list. Any time more are batched in, you'll want to add the batch size to your controller's total batched row count. This still lets the scroller zoom by rows the user couldn't distinguish at that speed anyway. You communicate the row count change to the table view by sending it -noteNumberOfRowsChanged and replying to its resulting data source request ( -numberOfRowsInTableView: ) with the updated total row count you stashed in a property of your controller. It'll ask for views for the newly visible rows as needed (which will be in some neutral, unfulfilled visual state until it's realized as before), update the scroll view, lather, rinse, repeat.
You could use NSCache to keep memory usage low. Set its countLimit to several times your batch size and let it drop previous batches if it decides it needs to dump the first n model objects, then batch them back in if the table view suddenly asks for a view for a row no longer in the batch window's range.
Without knowing more about your requirements and architecture, it's hard to get more specific. If I haven't hit the mark, consider editing your question to include more detail. If I'm totally off base from what you're asking for, please clarify. :-)
I know more about iOS, but I think the answer is similar. Table views are intrinsically finite, but you can roll your own custom scroll view to do this. The trick is to set a large content size and implement layout in your subclass (which will get called on every scroll change). In that method, check to see if the content offset is near zero or near the content size. If it is, then translate the content offset back to the center of the content size and translate all the subviews (keep them on one parent content view) by the same distance so the user doesn't see any motion. Make a datasource protocol and keep asking your datasource for "cells" that tile the visible part of the view.
It should be up to the datasource to recognize what we would have called a page-fault in the olden days, to decide that some of the model in memory should be discarded in favor of the model where the user is scrolling.
I poked around for an NS equivalent, but didn't see one on cursory search. Here's a decent-looking reference on the idea done in iOS.

Sync a slider with a text field in iOS

I'm totally new to iOS/objective-c and I got assigned a project to remove a few bugs in an iOS app and add some features.
What I'm trying to do at the moment is sync up a slider which represents a percentage with a newly added text field that can be fine tuned along with the slider. The key is that both are essentially synced up at the same time; if the user changes the slider to 75.2% for example, that same value must show up in the text field - and vice-versa.
I've done a lot of Googling around for this, but haven't been able to find much unfortunately. The class that manages everything is somehow synced up with .xib file. What would be nice to know is how one syncs these two together as well, and sets properties/events in the iOS Interface Builder which somehow effect the class.
So, how do these two aspects of iPhone development work?
I appreciate your time.

Making a chess multiplayer game

I am trying to make a Chess multiplayer game in Visual Basic. Its a two player which will be played in a normal way and not even over LAN.
So far, I am done designing the board.
My logic is:
First, on clicking any square, the click event handler will check whether a piece resides on that square. If not, then it checks if a piece is to be moved to that square. If both are negative, then it does nothing.
Now, the problem with this is, how do I code the click events? Also, I have represented the board using a 2dimensional array. But how do I update the positions after every move? And how do I check whether legal move is being executed? One more thing I want to add is whenever a piece is clicked, the possible legal squares should be highlighted.
For this, what I did was, for every click event on any square it checked if there was a piece. If there was a piece, then it highlighted all possible moves for that piece using If-Else-If logic, but it turned out to be too cumbersome and too long. And another problem which arose was, how do I know that if the user clicks an empty square to move the piece there?
Please help me.
"But how do I update the positions after every move?"
When the piece is about to be moved:
Check if the piece can move like that. (Like bishop can only move diagonally)
Check that your teams piece is not on the position your about to move.
Make a second array where the move is already happened.
Check if the move was legal. (Its your turn but the your king is kill-able with one move)
To check this you need:
To get your kings position
And then look up all the possible moves for the opponent
check if a move can land on your kings position.
This question is not really a good fit for Stack Overflow, but I will give you a pointer:
You need to create a class called ChessPiece
This will have properties like IsWhite and LocationX and LocationY that stores its current position on the board and PieceType which will be an enumeration like this:
Public Enum ChessPieceType
King
Queen
Bishop
Pawn
'etc
End Enum
You need to create some sort of array of these classes so that you have one for each piece on your board and you can set these positions manaully when the game starts.
When the user attempts to move a piece you check the PieceType enumeration to make sure that type of chess piece can actually move there, then check there isn't one of their own pieces on that square etc etc.