Foakx Posted March 14, 2020 Posted March 14, 2020 I try to make a Callback to the Client but the Arguments are undefined. If i Log one of the Arguments (Console.Log(argument)) it returns the correct value. //----------------------SERVER------------------------- mp.events.add("phone:insertNumber", (player, name) => { var number = Math.round(Math.random() * 1000000); db.insert(name, number); console.log(number); player.call("phone:callbackNumber", number); }); //----------------------CLIENT------------------------- mp.events.add("phone:callbackNumber", function(number) { mp.game.graphics.notify(toString(number)); telnumber = number; }); setTimeout(function () { mp.events.callRemote("phone:getNumber", name); }, 2000); In Console: Zitat Started HTTP server at 22006 port. (node:18348) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor. sendto failed with code -1 for char 5 and length 1464. sendto failed with code -1 for char 5 and length 1464. sendto failed with code -1 for char 5 and length 1464. sendto failed with code -1 for char 5 and length 1464. 284110 Ingame: Zitat [object Undefined] I don't know if there is a Bug with send Arguments
veers Posted March 15, 2020 Posted March 15, 2020 player.call("phone:callbackNumber", [number]); [] was missing!
Foakx Posted March 15, 2020 Author Posted March 15, 2020 vor 7 Minuten schrieb veers: player.call("phone:callbackNumber", [number]); [] was missing! Sorry it was the wrong code: p.events.add("phone:getNumber", (player, name) => { var entry = {}; db.numbers.forEach((val) => { if(val["username"] == name) { entry = val; } }); if(entry["username"] == null) { player.call("phone:callbackNotExist"); } else { var num = entry["number"]; console.log(num); player.call("phone:callbackNumber", num); } }); with [] it return undefined too.
Foakx Posted March 20, 2020 Author Posted March 20, 2020 I found my misstake: toString() is not working with Numbers I need to use ("" + number)
paccoderpster Posted April 4, 2020 Posted April 4, 2020 (edited) toString() works with numbers, you just used it wrong. The syntax is: object.toString() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString Edited April 4, 2020 by paccoderpster
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now