Author Topic: Code Check - Page 3  (Read 3110 times)

Do I make this a function? Package? Etc.
this is a code that belongs in a function

Code check. Im registering events that check if the client who activates the event initially has the same level as in the String box.
Code: [Select]
function fxDTSBrick::ifLevel(%client, %arg1)
{
if(%client.level == %arg1)
{
call(%client,"fxDTSBrick::ifLevelTrue");
}
else
{
call(%client,"fxDTSBrick::ifLevelFalse");
}
}
function fxDTSBrick::ifLevelTrue(%obj, %client)
{
$InputTarget_["Self"] = %obj;
$InputTarget_["Player"] = %client.player;
$InputTarget_["Client"] = %client;

if($Server::LAN)
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%client);
}
else
{
if(getMiniGameFromObject(%obj) == getMiniGameFromObject(%client))
$InputTarget_["MiniGame"] = getMiniGameFromObject(%obj);
else
$InputTarget_["MiniGame"] = 0;
}
%obj.processInputEvent("ifLevelTrue", %client);
}
function fxDTSBrick::ifLevelFalse(%obj, %client)
{
$InputTarget_["Self"] = %obj;
$InputTarget_["Player"] = %client.player;
$InputTarget_["Client"] = %client;

if($Server::LAN)
{
$InputTarget_["MiniGame"] = getMiniGameFromObject(%client);
}
else
{
if(getMiniGameFromObject(%obj) == getMiniGameFromObject(%client))
$InputTarget_["MiniGame"] = getMiniGameFromObject(%obj);
else
$InputTarget_["MiniGame"] = 0;
}
%obj.processInputEvent("ifLevelFalse", %client);
}
registerInputEvent("fxDTSBrick","ifLevelTrue","Self fxDTSBrick" "Player Player" "Client GameConnection" "MiniGame MiniGame");
registerInputEvent("fxDTSBrick","ifLevelFalse","Self fxDTSBrick" "Player Player" "Client GameConnection" "MiniGame MiniGame");
registerOutputEvent(fxDTSBrick,ifLevel,string 25 20);

Wait, where is %arg defined exactly.
Not too sure how events works yet, so this should be interesting.

The first argument when adding a method to an class should be a variable that represents the current object. By default, people use %this to  represents the actual block that is calling the ifLevel method you created. In the other methods you wrote, I see you represented the current object (which is the first argument) as %obj. I'm also not sure that call() is a method, but you can call the other methods like this below:
Code: [Select]
function fxDTSBrick::ifLevel(%this, %client, %arg1)
{
if(%client.level == %arg1)
{
%this.ifLevelTrue(%client);
}
else
{
%this.ifLevelFalse(%client);
}
}

I just skimmed over the first function which I noticed was very wrong. I haven't checked the others.

Come on man. At least test it before you ask what's wrong with it.

First of all,The event registry for the output event won't work because the string 25 20 part needs to be in parentheses.

First of all, what Static said. The first arg of the ifLevel method will always be a brick, because it's a method for fxDTSBrick. If you want %client to be an arg in that function, put a 1 as an arg when you register the output event(put it after the string part). Then %client will be the last arg of that function.

Also,
I'm also not sure that call() is a method
call(); and %whatever.call(); are both valid functions. He's totally using them wrong and without purpose, but they do exist. I suggest calling the functions in the way that Static suggested. An example of using call(); correctly: I have an item that squirts water. When the water hits something I use %obj.isFunction to check if the thing it hits does anything when it's hit with water. If the function exists I use %obj.call("onWaterHit"); to call that function.

That's really all I can see off the bat that you did wrong.

Also,call(); and %whatever.call(); are both valid functions. He's totally using them wrong and without purpose, but they do exist. I suggest calling the functions in the way that Static suggested. An example of using call(); correctly: I have an item that squirts water. When the water hits something I use %obj.isFunction to check if the thing it hits does anything when it's hit with water. If the function exists I use %obj.call("onWaterHit"); to call that function.
Thanks for clearing that up!