I have set up a (hash)map to hold vehicle inventory info on the server. When I try to fetch/get from client on the server, the serverside function doesnt seem to be able to read the map value.
Description
Details
- Severity
- Block
- Resolution
- Open
- Reproducibility
- Always
- Operating System
- Windows 10
- Category
- Scripting
Make a function that takes client id as a parameter, as well as a lookup key for a map. Then fill a global buffer with the map value inside the function, and transmit that back to the client with publicVariableClient. Using a regular array, this method shows up clientside with the value as intended, but with map instead, it fails to find the value and the client gets an undefined variable.
Do functions not remoteexec maps properly?
Event Timeline
Working code should look something like this, or not-working-code I should say:
//---global variables inventories = createHashMap; //add "map_key" value pair map_key="a map key string"; //map key inventories set [map_key, ["name",10] ]; //set random array-like value //name and inv size inv=[]; //global scope buffer variable, for both server and client //---add action [ player, ["get inv", { inv = ["",-1]; //make sure inv reset for wait [map_key, clientOwner] remoteexec ["AW_request_inventory",2]; //ask server for inv variable with function AW_request_inventory while { inv#1<0 } do { sleep .01 }; //wait for inv to update systemChat str inv; //this fails |#|inv undefined variable, if the function refers to a hashmap instead of an array, which works } ] remoteExec ["addAction", 0, true]; //add to every player, jip //---function to call from add action AW_request_inventory = { params [ "_name_string", "_request_id"]; inv = inventories get _name_string; //fill inv global buffer serverside //this works with an array, but not the new hashmap get _request_id publicVariableClient "inv"; //send variable "inv" to _request_id param, ie the player that requested it };
I think that should be easy to verify. The problem seems to be the function AW_request_inventory doesnt know about the map inventories in a way that it should. It does however know the contents of regular arrays. This is on dev branch and kind of hard to notice since its somewhat deep into the code.
There have been some changes/fixes in hash map since last dev, I suggest you try with new dev when it is out and report back
Your game should really be crashing instead of giving you undefined variables, i got a seperate report that reported crashing and could reproduce it, I don't know why your client isn't crashing, it should be.
I made a mistake in deserialization.
By the way I said on reddit that sending HashMaps over network is not very efficient, I take that back, its pretty good actually. But you still gotta keep in mind that you're always transferring the whole map.
sending the entire map is not an option. eventually it will be nested even, more like a collection of pointers to data for fast lookup. I want to send only the value located at key
so this will be fixed in the next dev branch update? any idea when it will be out? As my project largely will be on hold until then
cool. adding map is great I feel. it makes creating your own structs/objects almost possible