Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (degenerate_762, AndrewAMD), 877 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: reset function [Re: Realspawn] #423653
06/02/13 17:12
06/02/13 17:12
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
I'm not at home right now, I'll be back there in an hour or so, then I'll give you a working example.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: reset function [Re: Realspawn] #423655
06/02/13 17:13
06/02/13 17:13
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Please be more precise: When is this function supposed to end?


Always learn from history, to be sure you make the same mistakes again...
Re: reset function [Re: Uhrwerk] #423663
06/02/13 18:08
06/02/13 18:08

M
Malice
Unregistered
Malice
Unregistered
M



Really?


function loops once and is recursive
Code:
PANEL* looptxt_pan =

{

	bmap = "nextstage.tga";
	pos_x = 1054;
	pos_y = 350;
	layer = 50;	
}
function fnc_looptxt()
{
var my_start_x = looptxt_pan.pos_x;  // when the functions call store the start points
var my_start_y = looptxt_pan.pos_y;
	wait(3);
	set(looptxt_pan,SHOW | OVERLAY);
	while(looptxt_pan.pos_x < screen_size.x - bmap_width(looptxt_pan.bmap))	
{  // while loop till bmap is at edge of screen

		looptxt_pan->pos_x +=30* time_step; // simple pixel shift by time_step

		wait(1);
	}
looptxt_pan.pos_x = my_start_x;  // restore panels start points
looptxt_pan.pos_y = my_start_y;
fnc_looptxt();   // I used a recursive function but you could use other methods for repeating the action

}



Please answer Uhrwerks question.

@Realspwans a5 forum made me a life long acknex user !!!
@Realspawn remove the last line and call manually from another function.

@wjbender The only reason to have a globe var is if you need to evaluate it in more then one function. And you waste resource tracking it's state. A globe var is only needed if other functions need to know the state of this panels pos and they can get it also by comparing vars that are built in panel.pos_x < screen_size.x-bmap_width(panel.bmap). The only reason I can see to make a global var and track it is to save 2 seconds of code typing.


function loops by counter ... add counter as a passible argument.
Code:
PANEL* looptxt_pan =

{

	bmap = "nextstage.tga";
	pos_x = 1054;
	pos_y = 350;
	layer = 50;	
}
function fnc_looptxt(var max_loops)
{
var loop_counter = 0; // to track loops
/// var max_loops = 5 ; // set to your max loops
var my_start_x = looptxt_pan.pos_x;  // when the functions call store the start points
var my_start_y = looptxt_pan.pos_y;
	wait(3);
	set(looptxt_pan,SHOW | OVERLAY);
	while(loop_counter <= max_loops)	
{  
if(looptxt_pan.pos_x>= screen_size.x - bmap_width(looptxt_pan.bmap))
{
 loop_counter +=1;
looptxt_pan.pos_x = my_start_x;  // restore panels start points
looptxt_pan.pos_y = my_start_y;
}
		looptxt_pan->pos_x +=30* time_step; // simple pixel shift by time_step

		wait(1);
	}
}




Also it's good method to write generalized functions, You might only want to 'scroll' this one panel but getting into the habit of writing functions that can be reused is will help in coding bigger projects. When you can write functions(methods) for their 'jobs' and not for their current 'owner/user' ent.

So ...

Code:
PANEL* looptxt_pan =

{

	bmap = "nextstage.tga";
	pos_x = 1054;
	pos_y = 350;
	layer = 50;	
}
function fnc_rightscroll_pan(PANEL* this_pan, var scroll_speed)
{
var my_start_x = this_pan.pos_x;  // when the functions call store the start points
var my_start_y = this_pan.pos_y;
	wait(3);
	set(this_pan,SHOW | OVERLAY);
	while(this_pan.pos_x < screen_size.x - bmap_width(this_pan.bmap))	
{  // while loop till bmap is at edge of screen

		this_pan->pos_x +=scroll_speed* time_step; // simple pixel shift by time_step

		wait(1);
	}
this_pan.pos_x = my_start_x;  // restore panels start points
this_pan.pos_y = my_start_y;
}

fnc_rightscroll_pan(looptxt_pan,30);


Last edited by Malice; 06/02/13 20:57.
Re: reset function [Re: Realspawn] #423669
06/02/13 21:16
06/02/13 21:16
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: Realspawn
It works for now but i need to be able to reset this complete
function so it can be used all over when needed.
If I got you correct, you need to be able to call this function over and over again (for example from a key input, like - on_space).
And each time, it should place the panel at the start positions (default) and move, and if we call this function again, previous should terminate.

Here is the code (not tested, but should work):
Code:
PANEL* looptxt_pan = {
	bmap = "nextstage.tga";
	layer = 50;	
}

function looptxt(){
	
	wait(1);
	proc_kill(4);
	
	set(looptxt_pan, SHOW | OVERLAY);
	
	looptxt_pan.pos_x = 1054;
	looptxt_pan.pos_y = 350;
	
        // do here all manipulations you need
}



Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: reset function [Re: 3run] #423670
06/02/13 22:03
06/02/13 22:03

M
Malice
Unregistered
Malice
Unregistered
M



@3run if he is using one absolute panel with an absolute starting pos_x, why call the function just to kill it when you can compare? Is proc_kill faster?

Code:
if(key_space && looptxt_pan.pos_x == 1054)
{
looptxt();
}



Last edited by Malice; 06/02/13 22:32.
Re: reset function [Re: ] #423671
06/02/13 22:31
06/02/13 22:31
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Malice@ I don't really think that it's faster mate, I just wanted to give Realspawn an answer laugh I don't really know, what he is trying to archive, if we tries to loop the text on the screen, then using 'proc_kill' isn't needed at all I guess, it could be done with simple logic (if comparison).


Greets


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: reset function [Re: 3run] #423672
06/02/13 22:35
06/02/13 22:35

M
Malice
Unregistered
Malice
Unregistered
M



Quote:
I don't really know, what he is trying to archive

Yeah like Uhrwerk said the other day...
Quote:
Totally random guessing is a lot more fun

Re: reset function [Re: ] #423673
06/02/13 22:38
06/02/13 22:38
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: Malice
Yeah like Uhrwerk said the other day...
Quote:
Totally random guessing is a lot more fun
That made me ROFL grin

Realspawn@ if you need a scrolling (looping) text, take a look at this one:
Scrolling Text Request


Greets


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: reset function [Re: 3run] #423674
06/03/13 01:20
06/03/13 01:20
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
wow grinnn a lot of response laugh

sorry if i am not explaining all that good.
Let me try to use simple explenation.

When my player touches a certain object I need the sprite to
slide in from the right and then out to the left when it's off
screen (left) it should be reset to it's original start point
untill my player toches again the same object some where else in
the level laugh


Hope this cleares things up. Its 03:20 here so i get some sleep
and will tinker tomorrow some more laugh


Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: reset function [Re: Realspawn] #423675
06/03/13 01:47
06/03/13 01:47

M
Malice
Unregistered
Malice
Unregistered
M



I would think something like this... I still don't like the idea of using proc_kill this way.


Code:
PANEL* looptxt_pan =

{

	bmap = "nextstage.tga";
	pos_x = 0;
	pos_y = 350;
	layer = 50;	
}


function initialize_panel_startup()
{
looptxt_pan->pos_x -=bmap_width(looptxt_pan.bmap);
// any other data
}


function looptxt()
{
wait(3);
proc_kill(4);

var my_start_x = looptxt_pan->pos_x;  
var my_start_y = looptxt_pan->pos_y;
	
set(looptxt_pan,SHOW | OVERLAY);
while(looptxt_pan->pos_x < screen_size->x - bmap_width(looptxt_pan->bmap))	
{ 
looptxt_pan->pos_x +=30* time_step; 
wait(1);
}

looptxt_pan->pos_x = my_start_x;  
looptxt_pan->pos_y = my_start_y;
reset(looptxt_pan,SHOW );
}


function players_event()
{
if (event_type == EVENT_PUSH)
  {
looptxt();
}
// for more then a few event_type(s) use a 'switch'
}


action player_code()
{
.......
my.emask = ENABLE_PUSH;
my.event = players_event;
c_move(my,reldist,absdist,ACTIVATE_PUSH);
.......
}



You don't have to use ACTIVATE_PUSH is you set up the push values or see below for moving to event to the object and not the player.

Using a few global vars for tracking and comparing the running state of events is what I like but I don't know if it's faster.

Code:
var iEvent_pushRunning =0 ;

function looptxt()
{
iEvent_pushRunning =1; // new code for something like a keylock

var my_start_x = looptxt_pan->pos_x;  
var my_start_y = looptxt_pan->pos_y;
	
set(looptxt_pan,SHOW | OVERLAY);
while(looptxt_pan->pos_x < screen_size->x - bmap_width(looptxt_pan->bmap))	
{ 
looptxt_pan->pos_x +=30* time_step; 
wait(1);
}

looptxt_pan->pos_x = my_start_x;  
looptxt_pan->pos_y = my_start_y;
reset(looptxt_pan,SHOW );
iEvent_pushRunning =0; // release the lock
}


function players_event()
{
if (event_type == EVENT_PUSH && !iEvent_pushRunning) // only run if lock is open
  {
looptxt();
}
// for more then a few event_type(s) use a 'switch'
}




Event impact... Event run on object side, since the object is less likely to impact anything the event comparisons are run less often and save resources..


Code:
PANEL* looptxt_pan =

{

	bmap = "nextstage.tga";
	pos_x = 0;
	pos_y = 350;
	layer = 50;	
}


function initialize_panel_startup()
{
looptxt_pan->pos_x -=bmap_width(looptxt_pan.bmap);
// any other data
}

#define MAX_LEVEL_ENTS 200
#define EVENT_IMPACT_RUNNING skill20
#define LOCKED 1
#define UNLOCKED 0 

function looptxt()
{
my.EVENT_IMPACT_RUNNING = LOCKED;

var my_start_x = looptxt_pan->pos_x;  
var my_start_y = looptxt_pan->pos_y;
	
set(looptxt_pan,SHOW | OVERLAY);
while(looptxt_pan->pos_x < screen_size->x - bmap_width(looptxt_pan->bmap))	
{ 
looptxt_pan->pos_x +=30* time_step; 
wait(1);
}

looptxt_pan->pos_x = my_start_x;  
looptxt_pan->pos_y = my_start_y;
reset(looptxt_pan,SHOW );
my.EVENT_IMPACT_RUNNING = UNLOCKED;

}


function hit_object_event()
{
if (event_type == EVENT_IMPACT && !my.EVENT_IMPACT_RUNNING && you == player)
  {
looptxt();
}
// for more then a few event_type(s) use a 'switch'
}

action hit_object_code()
{
.......
my.emask = ENABLE_IMPACT;
my.event = hit_object_event;
my.EVENT_IMPACT_RUNNING =0;
.......
}




Last edited by Malice; 06/03/13 06:19.
Page 2 of 2 1 2

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