The online racing simulator
Message to just one person
Quote :
$this->MsgToAll($msg);

We have insim on our server and would like to change this code.

Does anyone know to make this code, so it sends to 1 person only, IE the person who asks the request...


Thank you
Mick
What framework are you using? Something created yourself, or something by filur, Dygear or someone else?

The reason I ask is that's very specific to whatever you're using, and isn't applicable to general insim programming.
It's easy with LFS External if you were using C#. MSN me and I'll try and give advice .

EDIT: IIRC In C# it would be InSim_MTC_MessageToConnection
EDIT 2: I think he is using PHP
Quote from the_angry_angel :What framework are you using? Something created yourself, or something by filur, Dygear or someone else?

I think he is using PHPLFS.

So really you would need to change it to something like this...

private function MsgToConnection($ucid, $message, $plid=0)
{
$this->server->sendp(new IS_MTC($ucid, "/msg $message", $plid));
}

If you wanted to be sent only to the person who asked the request, just make sure you put in their unique connection ID (ucid) to send the message to. But it is hard to be sure without more info.
[OT] What is the function of the PLID in a MTC? It functions perfectly with it set to 0... [/OT]
You can either use PLID or UCID. If you populate the UCID it will ignore the PLID.
I think it's the other way round, if you populate the PLID it will ignore the UCID. I might well be wrong though.

Just out of interest, does PHP let you use named parameters? Like this...
private function MsgToConnection($message, $ucid=0, $plid=0)
{
$this->server->sendp(new IS_MTC($ucid, "/msg $message", $plid));
}

$this->MsgToConnection("Hello, world!", $plid=12)

Quote from DarkTimes :I think it's the other way round, if you populate the PLID it will ignore the UCID. I might well be wrong though.

It's one way around or the other If you consider that they should be mutally exclusive then there's no real reason to get in a flap about which way around they should be used, I guess

Quote from DarkTimes :Just out of interest, does PHP let you use named parameters? Like this...

Yes it does.
Seem to be getting this error:
Fatal error: Class 'IS_MSC' not found in C:\LFS\PHP\programs\Stunt\Stunt.inc on
line 239
Quote from NabZ245 :Seem to be getting this error:
Fatal error: Class 'IS_MSC' not found in C:\LFS\PHP\programs\Stunt\Stunt.inc on
line 239

Should be MTC, not MSC. Maybe a typo by DarkTimes.
Yes, sorry, I made a typo. It should be IS_MTC.
LOL Another typo by DarkTimes . It is MTC not MST lol.
Whoops sorry. You'll see I actually updated my code posts to the correct thing, I just got brain fade when posting my reply.
That would be a good explaination, I should have realised that
Worked perfect. Thanks a lot guys
Quote from the_angry_angel :
Quote from DarkTimes :Just out of interest, does PHP let you use named parameters? Like this...

<?php 
private function MsgToConnection($message$ucid=0$plid=0)  {
    
$this->server->sendp(new IS_MTC($ucid"/msg $message"$plid));
}
$this->MsgToConnection("Hello, world!"$plid=12)
?>


Yes it does.

[offtopic]
And how did I not know this, this changes EVERYTHING! Oh god, I need to revisit my PHPInSim code, as this could make such a HUGE impact on it.

For those of you who did not notice named parameters, in this case it is $plid, if you did not name the parameter the value of 12 would of been passed to the $ucid variable and not the $plid variable. The first happens simply due to order of succession. However, you must know the name of the variable that you want to pass, and you have to give it a value in that same function call.
[/offtopic]
Quote from Dygear :named variables do not have to follow that order, they can be accepted in any order!

Unfortunately this isn't the case.


<?php 

    
function MsgToConnection($message$ucid=0$plid=0)
    {
        
var_dump($ucid$plid);
    } 
    
    
MsgToConnection('Hello, World!'$plid=12);

    function 
test($var1$var2$var3
    { 
        echo 
$var1$var2$var3PHP_EOL
    } 
     
    
test($var3='baz'$var2='bar'$var1='foo'); 
     
    
var_dump($var='value'); 

?>

Quote from filur :Unfortunately this isn't the case.

I was all giddy, I thought they did it the right way.
So PHP doesn't support those sorts of named parameters? I used to program PHP up until a few years ago and I didn't remember ever seeing them before, which is why I asked. I was a very bad PHP programmer though, so it wouldn't have surprised me if I missed something like that.
Bugger, sorry guys - I've caused some serious confusion here.

I skimmed the code in DarkTimes' post earlier today, and I clearly didn't read it properly I guess I assumed you were asking about predefining parameters (some how). I do apologise
Quote from the_angry_angel :Bugger, sorry guys - I've caused some serious confusion here.

I skimmed the code in DarkTimes' post earlier today, and I clearly didn't read it properly I guess I assumed you were asking about predefining parameters (some how). I do apologise

You so got my hopes up! But I forgive you.
Quote from Dygear :You so got my hopes up! But I forgive you.

Sorry I really need to stop partially reading posts :o I'm sure you realise this, but you can fake it, but it mings massively.

Or you can do it "the c way" and pass parameters into functions as arrays, and then array_merge them into some defaults.
Quote from the_angry_angel :but you can fake it

Yeah I could do it that way, but god, why would I want to.
And no one fakes it while I'm around. - Sorry, could not help it.

FGED GREDG RDFGDR GSFDG