quick question

Posted By: jigalypuff

quick question - 08/13/07 20:16

i am working on a recharge code and am useing morrowing as an example, i have the recharge and panels all working ok, and i wrote this bit of code as a small test, what should happen is the charge goes back to 0 and a sound should play, but neither happens, could someone point out were i`ve gone wrong please
Code:

function beam_weapons
{
if ((mouse_left == 1) && (player.phaser == 70))
{
player.phaser = 0;
snd_play (beam_wav, 50, 0);
}
}


Posted By: Bot190

Re: quick question - 08/13/07 22:09

well, the phasers energy has to be 70, guessing that player.phaser is the phasers energy. other than that i don't know. oh and try "on" instead of 1.
Posted By: jigalypuff

Re: quick question - 08/13/07 22:14

well ya but the phaser energy is up, that is all working ok, here`s the code for that.
Code:

panel Phaser_pan
{
bmap = charge_pan_tga;
pos_x = 945;
pos_y = 567;
window = 3, 2, 74, 7, charge_tga, player.phaser, 0; // can range from 0 to 74
flags = refresh, visible;
}

function init_player_startup()
{
while (player == null) {wait (1);}
player.phaser = 74;
while (1)
{
player.phaser += 0.4 * time; // increase power slowly
player.phaser = min(74, player.phaser); // limit phaser power 74
wait (1);
}
}


all this seems to work, and i assume at least the sound should play when i press the left mouse button.
Posted By: Bot190

Re: quick question - 08/13/07 22:17

well the way your code is writen the player.phaser has to be at 70 no more no less... so if its at 74 it won't work. and obviusly you have to have the sound file in the same foler. try switching the mouse thing.

[Edit] you didn't call the function that checks if you pressed the mouse button... or is it called somewhere? [Edit]
Posted By: LogantheHogan

Re: quick question - 08/14/07 01:15

Yeah, your function is increasing player.phaser by a TIME factor which makes it incredibly unlikely that player.phaser will ever be exactly equal to 70. either use the int() function to only look at the integer value of player.phaser, or change the comparison in the if statement to something like

if(player.phaser > 68 && player.phaser < 72) { blah }
Posted By: jigalypuff

Re: quick question - 08/14/07 14:02

i am useing on_mouse_left to activate the function.
logan i have tried what you suggested but it did not work, i suspect this is my fault though lol, how would you suggest i use the int() function? i don`t recall seeing that in the morrowing code at all.
here is what i tried.
Code:

function beam_weapons
{
if ((mouse_left == 1) && (player.phaser >68 && player.phaser <72))
{
player.phaser = 0;
snd_play (beam_wav, 50, 0);
}
}

on_mouse_left = beam_weapons;


Posted By: LogantheHogan

Re: quick question - 08/14/07 15:36

maybe if((mouse_left == 1) && int(player.phaser) == 70) {}

but I'd use an easier thing just for testing, and just say if((mouse_left == 1) && player.phaser > 70){}. See if that works.

Also, like Bot said, I saw no reference to the beam_weapons function in the other code you posted. make sure you're calling it somewhere, or make sure it's running somehow. if you're not, that is your problem.

EDIT: never mind. I just saw your last post when you referenced on_mouse_left. So that's not the problem.
Posted By: jigalypuff

Re: quick question - 08/14/07 15:42

woohoo cheers guys, it now works, any thoughts on how to get the energy to slowly deplete while the mouse button si pressed lol.
Posted By: LogantheHogan

Re: quick question - 08/14/07 19:04

Code:

var phaser_decreasing = 0;

function init_player_startup()
{
while (player == null) {wait (1);}
player.phaser = 74;
while (1)
{
if(phaser_decreasing == off)
{
player.phaser += 0.4 * time_step; // increase power slowly
player.phaser = min(74, player.phaser); // limit phaser power 74
}
wait (1);
}
}

function beam_weapons
{
while ((mouse_left == 1))
{
phaser_decreasing = on;
player.phaser -= 3*time_step;
snd_play (beam_wav, 50, 0);
wait(1);
}
phaser_decreasing = off;
}

on_mouse_left = beam_weapons;



By the way, don't use the TIME variable anymore. It's kinda not stylish these days. use time_step instead. Use it in the exact same way, just a different name. I replaced your TIME variables in the functions above with time_step already.
Posted By: jigalypuff

Re: quick question - 08/14/07 21:57

that works with just one little problem, when the power has been decreased i can keep fireing, it needs to actually not be able t owork if there is no power.
thanks for your help.
Posted By: LogantheHogan

Re: quick question - 08/14/07 22:07

Code:

function beam_weapons
{
while ((mouse_left == 1))
{
if(player.phaser <= 0) { break; }
phaser_decreasing = on;
player.phaser -= 3*time_step;
snd_play (beam_wav, 50, 0);
wait(1);
}
phaser_decreasing = off;
}


Posted By: Bot190

Re: quick question - 08/15/07 10:41

could you post the weapon code? oops didn't see logans post. oh and all that will do, atleast i think, is stop the energy decreasing it won't stop it from shooting. you should have a check in your shooting code if energy is <0 if so don't shoot.
Posted By: jigalypuff

Re: quick question - 08/15/07 16:11

spot on, thanks guys.
© 2024 lite-C Forums