Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (TipmyPip, 1 invisible), 18,789 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
can someone please correct this code? #373604
06/11/11 12:36
06/11/11 12:36
Joined: Jun 2011
Posts: 22
Germany
B
Bennett Offline OP
Newbie
Bennett  Offline OP
Newbie
B

Joined: Jun 2011
Posts: 22
Germany
I wanna be able to change weapons with some key, for example q.

this is above function_main and works:
Code:
TEXT* t_selected_weapon =
{
	pos_x = 0;
	pos_y = 0;
	layer = 1;
	string (str_selected_weapon);
	string (str_selected_number);
	flags = SHOW;
	
}



but this does not work:
Code:
while(1)
   {
   	if (key_q)
   	{
   		v_selected_wpn += 1;
			v_selected_wpn %= 2;
	
		if (v_selected_wpn == 1)
		{
			STRING* str_selected_number = "2";
		}
		if (v_selected_wpn == 0)
		{
			STRING* str_selected_number = "1";
		}


any tips?

Re: can someone please correct this code? [Re: Bennett] #373605
06/11/11 12:44
06/11/11 12:44
Joined: Nov 2010
Posts: 125
Germany
chrisp1 Offline
Member
chrisp1  Offline
Member

Joined: Nov 2010
Posts: 125
Germany
Code:
while(1)
   {
   	if (key_q)
   	{
   		v_selected_wpn += 1;
			v_selected_wpn %= 2;
	
		if (v_selected_wpn == 1)
		{
			STRING* str_selected_number = "2";
		}
		if (v_selected_wpn == 0)
		{
			STRING* str_selected_number = "1";
		}
wait(1);  ///////////////////////////////////////////// you forgot wait(1); ?
}



1. Did you forget a wait(1); ???
2. What happens when you run your script ???

Last edited by chrisp1; 06/11/11 12:46.

---------------------------------------------------
My new project: www.sfc.de.to
My old project: www.littlesubmarine.de.to
My Youtubechannel: http://www.youtube.com/user/darkchrisp#p/a/u/0/5idMXmCDdmA
---------------------------------------------------
Re: can someone please correct this code? [Re: chrisp1] #373608
06/11/11 12:56
06/11/11 12:56
Joined: Jun 2006
Posts: 379
Flevoland, 5 meters under wate...
Roel Offline
Senior Member
Roel  Offline
Senior Member

Joined: Jun 2006
Posts: 379
Flevoland, 5 meters under wate...
I think your code switches weapons very fast:
everytime the loop runs, and you still have the q key pressed, the weapons will switch again and again.


Code:
function switch_weapons()
{
   	v_selected_wpn += 1;
		v_selected_wpn %= 2;
	
	if (v_selected_wpn == 1)
	{
		STRING* str_selected_number = "2";
	}
	if (v_selected_wpn == 0)
	{
		STRING* str_selected_number = "1";
	}
}



and then somewhere else:

Code:
on_q = switch_weapons;



this makes your code run only once, when you press the q button

Last edited by Roel; 06/11/11 12:59.

Check out the throwing game here: The throwing game
Re: can someone please correct this code? [Re: Roel] #373620
06/11/11 13:56
06/11/11 13:56
Joined: Jun 2011
Posts: 22
Germany
B
Bennett Offline OP
Newbie
Bennett  Offline OP
Newbie
B

Joined: Jun 2011
Posts: 22
Germany
I changed it like Roel sujested, but nothing happens, just like before... is the mistake somewhere else?
Code:
BMAP* crosshair_pcx = "crosshair.pcx";
STRING* str_selected_weapon = "selected weapon:";
STRING* str_selected_number = "1";


var v_health = 100; //set Health to 100
var v_selected_wpn = 0; // weapon 1 selected

function switch_weapons()
{
   	v_selected_wpn += 1;
		v_selected_wpn %= 2;
	
	if (v_selected_wpn == 1)
	{
		STRING* str_selected_number = "2";
	}
	if (v_selected_wpn == 0)
	{
		STRING* str_selected_number = "1";
	}
}


TEXT* t_selected_weapon =
{
	pos_x = 0;
	pos_y = 0;
	layer = 1;
	string (str_selected_weapon);
	string (str_selected_number);
	flags = SHOW;
	
}

function main()
{
	video_screen = 1; //fullscreen
   video_mode = 8; // 1024*764
   level_load("Puschel.wmb");
   mouse_mode = 1;
   mouse_map = crosshair_pcx;
   on_q = switch_weapons;
   
   while(1)
   {
   	mouse_pos.x = screen_size.x /2 -bmap_width(crosshair_pcx)/2;// place crosshair in centre
		mouse_pos.y = screen_size.y /2 -bmap_height(crosshair_pcx)/2;// place crosshair in centre
		
		wait (1);
}
	mouse_spot.x = bmap_width(crosshair_pcx)/2;//set mouse pointer hotspot in middle
	mouse_spot.y = bmap_height(crosshair_pcx)/2;//set mouse pointer hotspot in middle
	 	
   }



Re: can someone please correct this code? [Re: Bennett] #373636
06/11/11 15:40
06/11/11 15:40
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
here's your problem!
Code:
.
	if (v_selected_wpn == 1)
	{
		STRING* str_selected_number = "2";
	}
	if (v_selected_wpn == 0)
	{
		STRING* str_selected_number = "1";
	}

you're not changing str_selected_number just creating a new local variable, use
Code:
str_cpy(str_selected_number, "1");



also, if you've only two weapons
Code:
v_selected_wpn += 1;
v_selected_wpn %= 2;

would be better written as
Code:
v_selected_wpn = 1 - v_selected_wpn;



Re: can someone please correct this code? [Re: MrGuest] #373638
06/11/11 15:53
06/11/11 15:53
Joined: Jun 2011
Posts: 22
Germany
B
Bennett Offline OP
Newbie
Bennett  Offline OP
Newbie
B

Joined: Jun 2011
Posts: 22
Germany
thank you very much!

so what does
Code:
str_cpy(str_selected_number, "1");


do exactly? I wanna understand it

Re: can someone please correct this code? [Re: Bennett] #373675
06/11/11 23:30
06/11/11 23:30
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
TEXT* is a struct for displaying strings onscreen.
str_cpy replaces the content of one string with something else, have a look in the manual at STRING str_cpy and str_cat which you'll probably need later

Re: can someone please correct this code? [Re: MrGuest] #373709
06/12/11 11:28
06/12/11 11:28
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
Manual !!!???


Gamestudio download | 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