Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, ozgur, AbrahamR, wdlmaster), 849 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 4 1 2 3 4
Re: Very confused... need advice... [Re: Jaeger] #266422
05/17/09 23:26
05/17/09 23:26
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
It doesn't even work like this...

if(key_f)
{
snd_stop(tankidle);
ent_playloop (my,tankidle, 77,0);
}

if(key_g)
{
snd_stop(tankidle);
}

There's just no way to stop the sound... I thought the problem was measuring key presses, variables, and if/else branching... But this is a shocker. I can't even use two separate keys to start/stop the sound? Makes no sense to me. I've done things like this before, and never had the problem...


Last edited by Jaeger; 05/17/09 23:28.
Re: Very confused... need advice... [Re: Jaeger] #266423
05/17/09 23:28
05/17/09 23:28
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
ahh, that functions doesn't work that way..


var handle = ent_playloop (my,tankidle, 77,0);
snd_stop(handle);


3333333333
Re: Very confused... need advice... [Re: Quad] #266426
05/17/09 23:51
05/17/09 23:51
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
This is really weird... I just did that, and it doesn't work. I can't get the loop to stop playing by any method... Ugh... I've got a fully working GUI that plays sounds and music, and stops them on command. However, this just won't do anything for me...

Am I overlooking some rules or concepts about these function commands (related to ent_playloop/sound) that's giving me so much grief?

Re: Very confused... need advice... [Re: Jaeger] #266432
05/18/09 00:25
05/18/09 00:25
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
heya, try something like
Code:
SOUND* snd_tankidle = ".wav"; //enter soundfile name here
var hnd_tankidle; //handle for playing soundfile

function toggle_engine(){
	
	//toggle to the new state
	engine_state = 1 - engine_state;
	
	//if engine is now on
	if(engine_state){
		hnd_tankidle = ent_playloop(panzer, snd_tankidle, 77);
		
	//if engine is now off
	}else{
		snd_stop(hnd_tankidle);
	}
}
//....

void main(){
	key_e = toggle_engine;
}
this is untested but will show you the use of sounds and handles

if this keeps switching on and off while you're pressing 'e', it'll be something inside you action, posting that code may help

hope this helps

Re: Very confused... need advice... [Re: MrGuest] #266435
05/18/09 00:53
05/18/09 00:53
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
This is what I just tried (shortened form), and I'm about to try your code and post the results...

Code:
//////////////////////////////////////////////////////////////////////////////////

SOUND* tankidle = "tankidle.wav";

....

var epressed = 0;

var tank_handle;

....

function start_eng();

...

function start_eng()
{
	if(epressed == 1)
	{
	
  	tank_handle = ent_playloop (panzer,tankidle, 77,0);
  	
  	epressed = 2;
  	}
  	
  	
  	if(epressed == 3)
  	{

	snd_stop(tank_handle);
	epressed = 0;
	
   }
	
}

....
// This part is inside the tank's action, not main()...
if(key_e)
  { 
    
    if(epressed == 0)
    {
    	epressed = 1;
    	start_eng();
    }
    
    if(epressed == 2)
    {
    	epressed = 3;
    	start_eng();
    }
    
  }
//////////////////////////////////////////////////////////////


It appears to me I did the if branching just fine, as each condition is met after pressing e multiple times, respectively. But for some reason, the snd_stop command just doesn't work in my code. I even tried writing it a few different ways (i.e., with "var tank_handle = ....", and without, plus several other ways). The loop starts, and there's nothing I can do to stop it, lol. This has made me waste almost a whole day. frown

Ok, well I'm going to try what you posted above, and tell you what happened...

Re: Very confused... need advice... [Re: Jaeger] #266438
05/18/09 01:14
05/18/09 01:14
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
@ Mr.Guest:

Your code worked almost perfectly. "E" starts the engine soundloop, and stops it... well, sometimes. For some reason, I have to wait about 3-5 seconds between keypresses. I guess that's not so bad, because a real Panzer IV would be about the same, heheh. You can't instantly start and stop it. But I would like to know why it does that.

Here's my source code, which is now working pretty much as I want it, with the exception of requiring the delay between keypresses...

Code:
///////////////////////////////////////////////////////////////////////////////////////////////////
// Icluding...
#include <acknex.h>
#include <default.c>
//
///////////////////////////////////////////////////////////////////////////////////////////////////
// Vehicle movement template... testing a tank... 
///////////////////////////////////////////////////////////////////////////////////////////////////

// Using the desert skirmish map, "Das Sandbox"...

// Declaring variables

var engine_state = 0;

var tank_handle;

var hnd_tankidle;

// Defining sounds

SOUND* snd_tankidle = "tankidle.wav";

//Declaring entity pointers

ENTITY* panzer;

// Defining movement vectors

VECTOR vSpeed, vAngularSpeed, vForce, vMove, vAhead;


// Declaring funtions

//////////////////////////////////////////////////////////////////////////////////////////////////
// Testing new function by MrGuest...                                                           //
//////////////////////////////////////////////////////////////////////////////////////////////////

function toggle_engine()
{
	
	//toggle to the new state
	engine_state = 1 - engine_state;
	
	//if engine is now on
	if(engine_state)
   {hnd_tankidle = ent_playloop(panzer, snd_tankidle, 77);}
		
	//if engine is now off
	else
	{
		snd_stop(hnd_tankidle);
	}
}


//////////////////////////////////////////////////////////////////////////////////////////////////


// Tank movement code...

// Defining actions

action tank_controls()
{
	wait(1);
   set(my,POLYGON); // Make the engine interpret collisions by the polygon and not bounding box
	
	// Set the tank's physical properties.
      phent_settype(my,PH_RIGID,PH_BOX);
      phent_setmass(my,2,PH_SPHERE);
      phent_setfriction(my,5);
      phent_setelasticity(my,7,100);
      phent_setdamping(my,27,5);
	

	while(1)
	{
		 // Update camera positions
      camera.x = my.x - 55;      // Position relative to tank's x position
      camera.y = my.y + 0;      // Position relative to tank's y position
      camera.z = my.z + 25;      // Position relative to tank's z position
      // Set camera tilt and pan in order to look at the tank.
      camera.tilt = -15;
      camera.pan = 0;
      wait(1);
      

    if(key_e) 
    {
    	toggle_engine();
    }
  
      //   Check to see if the player has fallen off the level i.e. the z value is less than minus 200
      if(my.z < -200)
      {
         phent_enable( me, 0 );      // To move physics enabled entities to an xyz position you must first disable physics for that entity
         my.x = 0;                  // Place at 0,0,80 (The 80 is so it spawns high enough above the level. You may need to change this with custom levels)
         my.y = 0;                  //
         my.z = 1000;
         phent_clearvelocity(my);   // Remove any speed and direction from the entity
         phent_enable( me, 1);      // Re-enable physics
      }
	}
}

// Collision detection/properties for objects
action terrain_prop()
{
   wait(1);
   c_updatehull(my,1);   // Update the "hull" of the object (helps engine with collisions)
   set(my,POLYGON);      // Make the engine interpret collisions by the polygon and not bounding box
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// MAIN ///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

function main()
{
	video_mode = 8;
	shadow_stencil= ON;
	video_screen = 1;
	mouse_mode = 0;
	wait(1);
	
	//load level "Das Sandbox"...
	level_load("tryintankin.wmb");
	wait(2);
	
	// Gravity
   ph_setgravity(vector(0,0,-500));
   
   // Create sky
   ent_createlayer("skycube+6.tga", SKY | CUBE | VISIBLE, 0); // Create a black backdrop for the level.
   wait(2);
   
   // create player/tank entity
   panzer = ent_create("panzerIV_sk_wip.mdl", vector(-488,-848,1500), tank_controls);
}



Can you explain to me why that worked and mine didn't? I'm just curious as to the difference. You know what they say, "Give a man a fish, and he eats for the day; teach a man to fish, and he eats for a lifetime..." laugh Well, you gave me the fish here. Can you tell me how you caught it? heheh...

Also, now that this works correctly, I can add something to my tank's action code like...

while(engine_state = 1)
{
...tanks movement/physics instructions here
}

...correct? That way, you can only drive the tank when the engine runs? That's how I originally planned to do this.

Thanks to all of you! I can't thank you enough for your time and patience! laugh

Re: Very confused... need advice... [Re: Jaeger] #266451
05/18/09 06:06
05/18/09 06:06
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
Ok, well I've made each track a separate entity, they are passable, and will stay with the model properly. The toggle_engine function doesn't like me anymore, since I've added new things. Before, it was really tricky to turn engine on/off, and I had to hit the button multiple times. Now it cranks, but once again, won't stop.

I just moved on, and I'll try to fix that later. I made a while(engine_state ==1) loop in the tanks action, and have successfully tuned the sound when I press the buttons.

But here's an odd problem. I was trying to use the dozer demo as reference for how to animate my tracks' skins. Then I discovered, I can't even run the dozer demo if I hit "test run". It won't compile. I wonder if this is because the author used a newer version of A7 than I? His .exe works fine, but the code crashes in SED for me. And, you guessed it, it crashes due to the coding to animate the tracks! frown What could be the cause of this?

But now, I don't know where to go about animating the tracks' skins... I guess I'll try a few things, and I hope to hear from you guys again soon.

Re: Very confused... need advice... [Re: Jaeger] #266465
05/18/09 08:05
05/18/09 08:05
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Well first you need make up your mind what problem you want to tell us, either the dozer wont compile, or it crashes, but hardly both at the same time.

When it wont compile, look at the line where an error is indicated, it probably uses a function that you dont have when your version is older. You should update your version then.

Your first code did not work because you were setting your "epressed" variable in such a strange way that the function was always called twice, and the sound was switched off immediately after it was switched on. Use the debugger, then you can easily see what happens in such cases. Without debugger, its just stumbling in the dark.

Re: Very confused... need advice... [Re: Tobias] #266466
05/18/09 08:26
05/18/09 08:26
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
The dozer demo won't compile. Sorry, don't know why I said "crashes" the second time.

" Error in Main line 142: 'u': is not a member of 'Entity' "

And that's where the coding for the little dozer's track animations go. However the dozer demo's .exe form works perfectly. That indicates to me my engine doesn't have something his does.

For my project, I tried a function like the one under the topic "vec_for_uv" in the manual. THAT made MY game crash. I usually need to see a good example of something to learn and understand it, and the example for this in the manual leaves me with nothing but questions. Trying to do a function like the one in the manual makes the compilation fail, due to the parameters in (). Without them, it compiles, but crashes when I try to run the function. And I don't understand why, because I've never seen this actually work, lol.

P.S.- I know why that first code I posted didn't work. Below I even said that it switched the sound on and off so fast it appeared nothing happened. It was just an example. The problem with the new code is that it no longer works if I add anything else to the program, and I just had to move on. At first, it worked... but only partially. It would switch on/off, but sometimes wouldn't. I had to wait several seconds between keypressed, and occassionally that wouldn't even work. Now it just doesn't shut off at all... again...

Re: Very confused... need advice... [Re: Jaeger] #266468
05/18/09 08:50
05/18/09 08:50
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
I believe 'u' was implemented some time ago, so your version must be very old, you should update it, its free.

vec_for_uv works in all versions. But when you omit parameters in an example, it of course will crash because then, the functions dont get valid parameters.

You will see that there are two sorts of examples in the manual. The newer functions have full examples that you can directly copy-paste in your code, or they are even full programs. Older functions have short examples that only show how to use the function. They are not copy-paste and require that you understand what a parameter is used for and so on. For instance, the vec_for_uv example expects that you have a global vector "temp" defined somewhere, like many other examples.

Just some advice, I would NOT "move on" when something does not work. You have to understand why it does not work. There is ALWAYS a good reason. I cant see it either in your code but thats why you have a debugger. If you just ignore a problem in your code because you dont see it at first, the problem will stay, and will affect your code further, causing delays, frustration and so on.

Make sure that you code works 100% and not only 90%. When there is an unexplained delay or you have to press a key several times, dont give up until you found the reason, and then you'll say "Ah, why didnt I see it at first?" Maybe you have several entities "Panzer" in your level, but your function only works when there is only one. Or something like that.

Just some piece of advice from a fellow programmer who made the very same experiences with the first steps of programming.

Page 2 of 4 1 2 3 4

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1