The online racing simulator
#1 - PoVo
Multi-Classed Plugin
Hi,

I was wondering if it's possible to create a multi classed plugin in PRISM?

Let's say we have the main class - game.php.

Now I also want to add game_utilities.php which would contain functions.

Now let's say I have the usual stuff in game.php like the constructor along with a variable
var $my_array = array();

Now I also want to add a function in game_utilities.php called "performChanges()".

The bit that I'm stuck on is allowing the game_utilities.php to access the $my_array variable.

Is this possible?

Another goodie would be to be able to send / receive InSim packets from the game_utilities.php class.

Any suggestions?

Thanks!
Quote from PoVo :Hi,

[1]I was wondering if it's possible to create a multi classed plugin in PRISM?

Let's say we have the main class - game.php.

[2]Now I also want to add game_utilities.php which would contain functions.

[3]Now let's say I have the usual stuff in game.php like the constructor along with a variable
var $my_array = array();

Now I also want to add a function in game_utilities.php called "performChanges()".

The bit that I'm stuck on is allowing the game_utilities.php to access the $my_array variable.

Is this possible?

[4]Another goodie would be to be able to send / receive InSim packets from the game_utilities.php class.

[5]Any suggestions?

Thanks!
  1. Yes it is. Anything that can be done in PHP can be done in PRISM, I don't have the power to restrict the language at all.
  2. I'm not quite sure what you mean here. There are many ways to handle this so if you could give me a full example, php code, of what you want to do I'll tell you if that's how I would set it up, or you could just run a pilot example and see if that works.
  3. Depending on how you set it up, if you simply have game_utilities class extend the game class then it's really simple to use on function within the other. However, if you want to use two separate classes, then you would have to make $my_array public, in fact the syntax you have right now automatically makes it public.
  4. You can send packets from anywhere within the PRISM instance, plugins, modules, or the core. (However, I'll pretty much be the only one sending packets from the core.) Any class that is made, as long as it uses the prism_packets.php instance module should be able to send the packet from PRISM. (Although, I've never really tried.)
  5. As far as suggestions. I would recomend making the game plugin, into a module as I think that's more of what you want. It would act as a layer between the PRISM core and your plugin. But I still don't know what you have planned so if you could provide some more details and what exactly you want to do that would help me help you. Even better then that write me to pseudo code and I'll tell you from there what's the best way to handle it within PRISM.
#3 - PoVo
Thanks for the reply. I'll write an example code today later on.

Another question I have is why do I keep getting errors like:
IS_MTC - first byte must not be zero

My message is like so:
$MTC->UCID($NPL->UCID)->ReqI(1)->Msg('^B^3» ^1You are disallowed to join the track!')->Send();

The MTC struct has changed in the newest versions of LFS, Scawen changed the Msg property to Text. So you'll have to use that from now on. Just replace Msg with Text and it should go away. Also make sure you're using the latest version of PRISM.
#5 - PoVo
Alright, so I have made a little example plugin.

Here is PlugName.php:

<?php 
php
include 'PlugName_Utils.php';

class 
PlugName extends Plugins
{
    const 
URL '-';
    const 
NAME '-';
    const 
AUTHOR '-';
    const 
VERSION PHPInSimMod::VERSION;
    const 
DESCRIPTION '-';

    var 
$data = array();
    
    public function 
__construct()
    {
    
DoFunction(); # function from PlugName_Utils.php
    
}
}
?>

Here is PlugName_Utils.php:

<?php 
php

public function DoFunction()
{
    
$data['Povo']['Place'] = 'Random Place!';
    
$MST = new IS_MST();
    
$MST->Msg('/msg Data Updated')->Send();
}

?>

This is briefly what I want to do. Any suggestions?
Can't you just pass the $data variable to the function as a parameter?


<?php 
public function DoFunction($data) {

}

DoFunction($this->data);
?>

#7 - PoVo
Well yeah, but that won't let me change info in the $data variable.

I would have to return it and re-set the variable. I would also like to access functions from other classes so it wouldn't work
OK, you might need to wait for a PHP programmer to turn up, but sounds like you would need to pass the array by reference, which I believe you would do like this.

public function DoFunction([b]&[/b]$data) {

}

Check out this page from the docs.

http://php.net/manual/en/language.references.pass.php
Ok, that's not going to work, but you could do a chain extension, where one class extends another, extends another until you have all the parts you need. It would look something like this:

povo.php

<?php 
php
include 'povo_utils.php';
class 
povo extends povo_utils
{
    const 
URL '-';
    const 
NAME '-';
    const 
AUTHOR '-';
    const 
VERSION 'This can be anything by the way, and really you should set it to not be that of PHPInSimMod\'s Version';
    const 
DESCRIPTION '-';

    public 
$data = array();
    
    public function 
__construct()
    {
        
$this->doFunction(); # function from povo_utils.php
    
}
}
?>

povo_utils.php

<?php 
php
class povo_utils extends Plugins
{
    public function 
doFunction(&$data $this->data)
    {
        
$data['Povo']['Place'] = 'Random Place!';
        
$MST = new IS_MST();
        
$MST->Msg('/msg Data Updated')->Send();
    }
}
?>

#10 - PoVo
Thanks for that!

Another problem I'm having is receiving MCI packets. I've binded my the ISP_MCI packet to my MCI function is the _construct, and it simply doesn't receive packets.

I have set my hosts config PPS to 2.

As far as I know I have to enable it in the ISI flags, but can't seem to know how to do it with PRISM
Quote from PoVo :I've binded my the ISP_MCI packet to my MCI function is the _construct, and it simply doesn't receive packets.

I'm not sure what you mean, it's normally better to just post the code and then to state the problem. It let's me know what your trying to do, and let's me see how your trying to do it.
Quote from Dygear :I'm not sure what you mean, it's normally better to just post the code and then to state the problem. It let's me know what your trying to do, and let's me see how your trying to do it.

He meant, he put the line which assigns a function to the MCI Packet...
Quote from PoVo :Thanks for that!

Another problem I'm having is receiving MCI packets. I've binded my the ISP_MCI packet to my MCI function is the _construct, and it simply doesn't receive packets.

I have set my hosts config PPS to 2.

As far as I know I have to enable it in the ISI flags, but can't seem to know how to do it with PRISM

if you have the latest version, go to configs, and then open host.ini, and add this line to your host:

This includes ISP_CON

<?php 
flags 
104
?>


If you don't want it:


<?php 
flags 
40
?>


should look like this:


<?php 
[localhost]
ip "localhost"
port 29999
socketType 
1
pps 
4
flags 
104
?>


#14 - PoVo
Thanks T3charmy, worked like a charm
Ok .

FGED GREDG RDFGDR GSFDG