Author Topic: Toggle mode script giving errors  (Read 2323 times)

Here's what I have, I'll show you when the error report in the console is using ##'s.

Code: [Select]
function serverCmdtogglestarmode(%client)
{
if(%client.mode $="1"){

starGunProjectile::onCollision(%this, %obj, %col, %fade, %pos, %normal)##{
if(%col.getClassName() $= "fxDTSBrick"){
%col.killBrick();
}
}

starGunImage::OnMount(%this, %obj){
Parent::OnMount(%this);
%client = %obj.client;
if(!%client.isAdmin || !%client.isSuperAdmin){
%client.player.unMountImage("starGunImage");
}
}

serverCmdstarGun(%client){
if(%client.isAdmin || %client.isSuperAdmin){
%client.player.MountImage("starGunImage",0);
%client.player.playThread(0,armreadyright);
}
}
messageAll("","\c3Star Gun is in \c0Destroy Mode");
}
if(%client.mode$ $="0") {
return;
messageAll("","\c3Star Gun is in \c0Normal Mode");
}
}

What did I do wrong?

Umm, you can't define methods inside a method.

Here's what I have, I'll show you when the error report in the console is using ##'s.

Code: [Select]
function serverCmdtogglestarmode(%client)
{
if(%client.mode $="1"){

starGunProjectile::onCollision(%this, %obj, %col, %fade, %pos, %normal)##{
if(%col.getClassName() $= "fxDTSBrick"){
%col.killBrick();
}
}

starGunImage::OnMount(%this, %obj){
Parent::OnMount(%this);
%client = %obj.client;
if(!%client.isAdmin || !%client.isSuperAdmin){
%client.player.unMountImage("starGunImage");
}
}

serverCmdstarGun(%client){
if(%client.isAdmin || %client.isSuperAdmin){
%client.player.MountImage("starGunImage",0);
%client.player.playThread(0,armreadyright);
}
}
messageAll("","\c3Star Gun is in \c0Destroy Mode");
}
if(%client.mode$ $="0") {
return;
messageAll("","\c3Star Gun is in \c0Normal Mode");
}
}

What did I do wrong?

Code: [Select]
1.function serverCmdtogglestarmode(%client)
2.{
3. if(%client.mode $="1"){
4.
5. starGunProjectile::onCollision(%this, %obj, %col, %fade, %pos, %normal)##{
6. if(%col.getClassName() $= "fxDTSBrick"){
7. %col.killBrick();
8. }
9. }
10.
11. starGunImage::OnMount(%this, %obj){
12. Parent::OnMount(%this);
13. %client = %obj.client;
14. if(!%client.isAdmin || !%client.isSuperAdmin){
15. %client.player.unMountImage("starGunImage");
16. }
17. }
18.
19. serverCmdstarGun(%client){
20. if(%client.isAdmin || %client.isSuperAdmin){
21. %client.player.MountImage("starGunImage",0);
22. %client.player.playThread(0,armreadyright);
23. }
24. }
25. messageAll("","\c3Star Gun is in \c0Destroy Mode");
26.}
27. if(%client.mode$ $="0") {
28. return;
29. messageAll("","\c3Star Gun is in \c0Normal Mode");
30. }
31.}

Lines 5, 11, 19: Are you defining functions here? You're already in a function!

Lines 19 and 20: You're missing a closing bracket for one of these.

Line 25: I think this is for if the client's mode is 1 (destory mode). If that's the case then it should be inside the brackets for that (in other words, switch lines 24 and 25).

Line 26: This looks like it's ending the function... in fact I think this should just be deleted.

Line 27: %client.mode$ $= should be changed to %client.mode $=.

Line 28: return; will completely exit the function, but you're still calling commands on line 29. If you want the command on line 29 to be called, switch lines 28 and 29.


The best advice I can give you is to try using some kind of IDE, like Notepad++ or something that can help keep your code properly indented.

Otherwise the only thing I saw wrong was that it looked like you were defining methods inside of a function... that's a big no-no in torquescript.
« Last Edit: November 18, 2007, 04:42:49 PM by exidyne »

I just want to make it so that if it's in destroy mode it can destroy bricks with the projectile, if not then it can't.

Code: [Select]
function serverCmdToggleStarMode(%client) {
   if( %client.mode == 1 ) {
      // They're in mode 1, let's change it to mode 0
     %client.mode = 0;

     messageClient(%client, '', '\c3Star Gun is in \c0Destroy Mode');
   } else {
      // They must be in mode 0, so let's change it to mode 1
      %client.mode = 1;

      messageClient(%client, '', '\c3Star Gun is in \c0Normal Mode');
   }
}

This is just to switch the modes for the client. To actually change what the star gun does, you'd have to make to make the function starGunProjectile::onCollision() and use if( %client.mode == 1 ) to figure out what to do.
« Last Edit: November 18, 2007, 04:43:53 PM by exidyne »

You can't define what the oncollision is doing without defining methods so I guess it's impossible.

And I always use Notepad 2 for all my scripting, which is like Notepad 1 + tons of new features and scripting languages.

It's possible, just make the onCollision() method separately, and inside it figure out what to do by checking whether the client (use the arguments to get the client) is in mode 0 or 1.

Code: [Select]
function serverCmdtogglestarmode(%client)
{
if(%client.smode $="0"){
%client.smode = "1";
messageAll("","\c3Star Gun is in \c0Destroy Mode");
}
else{
if(%client.smode $="1"){
%client.smode = "0"
messageAll("","\c3Star Gun is in \c0Normal Mode");
}
}
}
starGunProjectile::onCollision(%this, %obj, %col, %fade, %pos, %normal){
if(%col.getClassName() $= "fxDTSBrick"&&%obj.client.smode$="1"){
%col.killBrick();
}
else{
parent::onCollision(%this,%obj,%col,%fade,%pos,%normal);
}
}

starGunImage::OnMount(%this, %obj){
Parent::OnMount(%this);
%client = %obj.client;
if(!%client.isAdmin || !%client.isSuperAdmin){
%client.player.unMountImage("starGunImage");
}
}

function serverCmdstarGun(%client){
if(%client.isAdmin || %client.isSuperAdmin){
%client.player.MountImage("starGunImage",0);
%client.player.playThread(0,armreadyright);
}
}
fixed a problem in the code.
« Last Edit: November 18, 2007, 05:25:25 PM by rkynick »

You need to use the word function to define a function.

You also forgot a semi-colon somewhere, and didn't include an argument for Parent.

Also, this may not be very necessary but you should use %client.mode == 1 rather than %client.mode $= "1".
Code: [Select]
function serverCmdtoggleStarMode(%client) {
if(%client.smode == 0){
%client.smode = 1;
messageAll('', '\c3Star Gun is in \c0Destroy Mode');
} else {
%client.smode = 0;
messageAll('', '\c3Star Gun is in \c0Normal Mode');
}
}

function starGunProjectile::onCollision(%this, %obj, %col, %fade, %pos, %normal) {
if(%col.getClassName() $= "fxDTSBrick" && %obj.client.smode == 1)
%col.killBrick();
else
Parent::onCollision(%this, %obj, %col, %fade, %pos, %normal);
}

function starGunImage::onMount(%this, %obj) {
Parent::onMount(%this, %obj);

%client = %obj.client;
if(!%client.isAdmin || !%client.isSuperAdmin)
%client.player.unMountImage("starGunImage");
}

function serverCmdstarGun(%client) {
if(%client.isAdmin || %client.isSuperAdmin) {
%client.player.mountImage("starGunImage", 0);
%client.player.playThread(0, armreadyright);
}
}
« Last Edit: November 19, 2007, 03:31:53 PM by exidyne »

Umm, I don't think Blockland / Torque can handle doing an "unmount" of an image within that image's "onMount" method call.  You need to schedule the unmount.

Code: [Select]
schedule(50,0,"methodname");
Then, make the "methodname" method call the unmount code.

Umm,
Umm,

If it was a method you were scheduling then it would be
Code: [Select]
[obj].schedule( [time], "methodname");

No.  You can just use this:

Code: [Select]
schedule(50,0,"methodname",<args>);
The %obj.schedule is not necessary.

You seem not to be very familiar with the inner workings of TorqueScript.  This is the second time you've tried to correct me, and the second time where you weren't quite correct.
« Last Edit: November 19, 2007, 02:56:44 PM by Trader »

you weren't quite correct.

Actually, you just used the wrong term.
I thought you'd have picked up by this by now, but a method is different than a function, because it's being called on an object. So if you scheduled a method, you'd use the schedule method, not the schedule function.

Perhaps in other programming languages, separating the two terms would actually matter.  But because TorqueScript declares both types of calls using "function", it really doesn't matter.

Code: [Select]
function test()
{
}

function testobject::test()
{
}

It makes no difference, whatever you want call them.  We've only managed to get away from the point of my post.  Torque doesn't like performing weapon image unmount calls during that same image's onMount call.  So schedule the image unmount.

Yeah... but it would still be
Code: [Select]
%client.player.schedule(50, "unMountImage", "starGunImage");
in the onMount() method.

Torque also has problems with
Code: [Select]
schedule(1000, 0, "eval", ...)
« Last Edit: November 19, 2007, 03:22:26 PM by exidyne »