Author Topic: Torque is drunk  (Read 847 times)

It doesn't seem to be obeying the laws any other programming language should, such as only doing commands in if statements if the statement is met. Let me give you an example:
Code: [Select]
function GameConnection::spawnPlayer(%Client)
{
echo("SpawnHit");
parent::spawnPlayer(%Client);
%basePlayerSpeed = %client.player.getDatablock().maxForwardSpeed;
%randNum = getRandom(0,1);
echo(%randNum);
echo("SpawnParentPassed");
if(%randNum == 1){
echo("if hit");
changeSpeed(%client, 30);
messageAll('BoostSoundEmitter','\c1%1 recieved boost', %client.name);
ServerPlay2D(boostSound);
}
}
It will go through, hitting the echos properly. But sometimes, for some reason, it only does half the commands. For example, my echos tell me that the if was hit, and I get the chat message, but then I get no speed boost or sound. Then on another occasion my echos report that the if statement wasn't hit, but the sound plays anyway. Sometimes none of the if commands happen upon hit, sometimes all. I'll just clarify some things I've tried:
-This is properly packaged and activated. All the other function overwrites work just dandy as far as I've seen.
-changeSpeed, messageAll, and ServerPlay2D have all worked just fine in their current states, but often just seem to choose not to at random times for no reason

The first thing you'll probably think is that I'm making some sort of pathetic joke. But I'm not. I have tried over and over again and nothing is working. I've shown the code to Jetz and he confirmed that it should work fine. I just don't know what's going on. Is there some small thing I'm doing that I've been missing all this time? Or does Torque just hate me?

I remember hearing that you've restarted before, but I need to confirm: Is the code inside a zip?
If so, you need to make sure that you've both properly updated the zip with the proper code, and that you do discoverFile("add-ons/blah_blah.zip"); before executing.
You also need to make sure that there are no other packages that are playing that sound.

I remember hearing that you've restarted before, but I need to confirm: Is the code inside a zip?
If so, you need to make sure that you've both properly updated the zip with the proper code, and that you do discoverFile("add-ons/blah_blah.zip"); before executing.
You also need to make sure that there are no other packages that are playing that sound.
I'm running it from inside a folder, so unfortunately that doesn't apply. And I save frequently, and changes to things like the echoes and the message show up too. I also thought you might be on to something with the other packages thing, but besides Gamemode_Zombie, Slayer, and a few weapons, I have nothing besides defaults. And to check, I removed all non-default addons from my folder and it still is acting wonky. And I've always had every other addon disabled at some point.
Oh, and the sound is a datablock I created myself, not something default another addon would use.

I can see absolutely no reason why this wouldn't be working, so I'll try to run the code myself sometime tomorrow. Can you provide the full area of the code along with the definition of the boost sound?

Exactly as it is, with code completely unrelated removed.

Code: [Select]
datablock AudioProfile(sanicSound)
{
filename    = "./sanic.wav";
description = AudioDefault3D;
preload = true;
};

function changeSpeed(%client, %speed){
%client.player.getDatablock().maxForwardSpeed = %speed;
}

if(getActivePackage(dankify))
   deActivatePackage(dankify);
package dankify {
function GameConnection::spawnPlayer(%Client)
{
echo("SpawnHit");
parent::spawnPlayer(%Client);
%basePlayerSpeed = %client.player.getDatablock().maxForwardSpeed;
%randNum = getRandom(0,1);
echo(%randNum);
echo("SpawnParentPassed");
if(%randNum == 1){
echo("forget you torque");
changeSpeed(%client, 30);
messageAll('sanicEmitter','\c1%1 are becom fast!!', %client.name);
ServerPlay2D(sanicSound);
}
}
};activatePackage(dankify);

Note: I tried isolating it too, still didn't work.
« Last Edit: May 24, 2015, 12:56:34 AM by Narkro555 »

FYI there is a player.setMaxForwardSpeed /sidespeed/backwardspeed method now which is far more appropriate than globally updating the datablock like here.

FYI there is a player.setMaxForwardSpeed /sidespeed/backwardspeed method now which is far more appropriate than globally updating the datablock like here.
Correct. Use this instead.
Code: [Select]
datablock AudioProfile(sanicSound)
{
filename    = "./sanic.wav";
description = AudioClose3d;
preload = true;
};

function Player::setBaseMovementSpeed(%this, %value)
{
%value = mClampF(%value, 0, 200);
%this.setMaxForwardSpeed(%value);
%this.setMaxBackwardSpeed(%value);
%this.setMaxSideSpeed(%value);
%this.setMaxCrouchForwardSpeed(%value);
%this.setMaxCrouchBackwardSpeed(%value);
%this.setMaxCrouchSideSpeed(%value);
}

if(getActivePackage(speedOnSpawn))
deactivatePackage(speedOnSpawn);

package speedOnSpawn
{
function GameConnection::spawnPlayer(%this)
{
Parent::spawnPlayer(%this);
if(getRandom(0, 1) == 1)
{
messageAll('sanicEmitter','\c1%1 are becom fast!!', %this.name);
ServerPlay2D(sanicSound);
%this.player.setBaseMovementSpeed(30);
}
}
};
activatePackage(speedOnSpawn);
This should work.

-snip-
This should work.

Well, after all this time, something finally works. Maybe it was messing with that datablock inherently messed things up, but this is such a relief. Thank you.