Page MenuHomeFeedback Tracker

Problem fetching hashmap value from server (sqf scripting)
Closed, ResolvedPublic

Description

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.

Details

Severity
Block
Resolution
Open
Reproducibility
Always
Operating System
Windows 10
Category
Scripting
Steps To Reproduce

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

Jabulon created this task.Sun, Jan 31, 1:13 PM
BIS_fnc_KK changed the task status from New to Need More Info.Sun, Jan 31, 7:16 PM
Jabulon added a comment.EditedSun, Jan 31, 8:11 PM

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

dedmen claimed this task.EditedMon, Feb 1, 10:35 AM
dedmen changed the task status from Need More Info to Assigned.
dedmen added a subscriber: dedmen.

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

dedmen changed the task status from Assigned to Feedback.Mon, Feb 1, 1:11 PM

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

dedmen added a comment.Mon, Feb 1, 6:16 PM

Yes it will. This week there will be one but I'm not sure if it made it into there.

Jabulon added a comment.EditedMon, Feb 1, 7:49 PM

cool. adding map is great I feel. it makes creating your own structs/objects almost possible

dedmen closed this task as Resolved.Mon, Feb 22, 5:43 PM