reset function

Posted By: Realspawn

reset function - 06/01/13 14:46

How could I make this function reset. So the picture get's
placed at it's original start point ?

Code:
PANEL* looptxt_pan =

{

	bmap = "nextstage.tga";
	pos_x = 1054;
	pos_y = 350;
	layer = 50;	
}
function looptxt()
{

	wait(3);
	set(looptxt_pan,SHOW | OVERLAY);
	while(1)
	{
		looptxt_pan->pos_x = cycle(looptxt_pan->pos_x -30 * time_step,-bmap_width(looptxt_pan->bmap),screen_size.x);
		wait(1);
	}
}



It works for now but i need to be able to reset this complete
function so it can be used all over when needed.


Thx for your time laugh
Posted By: Wiseguy

Re: reset function - 06/01/13 15:19

Not to sound rude, but you've got to be kidding, right? I mean, you've over 4k posts and are apparently a long time user and even a moderator.
Posted By: krial057

Re: reset function - 06/01/13 16:03

Just set the position to the original position at the start of the function. You could use defines to make the code easier to customize:
Code:
#define LOOPTXT_PAN_ORIGINAL_X 1054
#define LOOPTXT_PAN_ORIGINAL_Y 350
PANEL* looptxt_pan =

{

	bmap = "nextstage.tga";
	pos_x = LOOPTXT_PAN_ORIGINAL_X ;
	pos_y = LOOPTXT_PAN_ORIGINAL_Y ;
	layer = 50;	
}
function looptxt()
{
	wait(3);
	looptxt_pan->pos_x = LOOPTXT_PAN_ORIGINAL_X ;
	looptxt_pan->pos_y = LOOPTXT_PAN_ORIGINAL_Y ;
	set(looptxt_pan,SHOW | OVERLAY);
	while(1)
	{
		looptxt_pan->pos_x = cycle(looptxt_pan->pos_x -30 * time_step,-bmap_width(looptxt_pan->bmap),screen_size.x);
		wait(1);
	}
}

Posted By: Realspawn

Re: reset function - 06/01/13 16:12

thank you laugh

As i always mention i am a non coder laugh have a fulltime job
and do this in my free time for fun laugh so nope i am not kidding laugh
the number of posts and the fact that i moderate has nothing to do with me not beeing a coder laugh Although i understand why people think that.

I like to toy with 3DGS and enjoy seeing enough people out here still willing
to help out. All i do know and learn is on my noob site laugh so people like me
can still try to create fun things laugh

I will always envy those fast coders wink





Posted By: Wjbender

Re: reset function - 06/01/13 16:19

You could do it in another way aswell..
(dont be so modest , everyone can code and everyone who can code needs help one time or another)

If you used a variable of integer instead of
while(1) like while(not_reached_border)
then when your x position reaches your req x position set not_reached_border to 1..

This will help to exit the while loop if you dont want it to loop all the time..
Posted By: Anonymous

Re: reset function - 06/02/13 00:55

Quote:
If you used a variable of integer instead of
while(1) like while(not_reached_border)
then when your x position reaches your req x position set not_reached_border to 1..


Why would you do this? 'while' is a comparison.
Code:
while(pan->pos_x < screen_size.x- bmap_width(pan->bmap)){ ...code...  
wait(1);}
.. then restore pan->pos_x to your save starting points...



Why create variable?
Posted By: Wjbender

Re: reset function - 06/02/13 08:53

Because you could globaly reset that variable and your code comes dow. To the same thing an evaluation ..(malis)

By the way if your going to respond to someone asking help be fucking friendly not a dickhead(wiseguy)
Posted By: Realspawn

Re: reset function - 06/02/13 10:27

@ krial

I tried your code but the i get number syntax errors ?
pos_x = LOOPTXT_PAN_ORIGINAL_X ;
pos_y = LOOPTXT_PAN_ORIGINAL_Y ;

perhaps i need to do something extra that I simply don't see
Posted By: krial057

Re: reset function - 06/02/13 12:40

Oh, my bad. Didn't know about this:

Quote:
Within the struct initialization, any numbers, variables, character strings, or pointers to other structs can be used, but internal engine variables (such as "camera"), and #defines (such as a previously defined "NUMBER_OF_ARRAY_ELEMENTS") can not be used.


I tried using variables instead of defines, but that doesn't work either frown (However, as I understand the manual, it should... I tested using variables in custem defined structs and there it works...)

If you are only using looptxt to show the panel, you could emit the position initialisation in the panel definition:

Code:
#define LOOPTXT_PAN_ORIGINAL_X 1054
#define LOOPTXT_PAN_ORIGINAL_Y 350
PANEL* looptxt_pan =

{

	bmap = "nextstage.tga";
	layer = 50;	
}
function looptxt()
{
	wait(3);
	looptxt_pan->pos_x = LOOPTXT_PAN_ORIGINAL_X ;
	looptxt_pan->pos_y = LOOPTXT_PAN_ORIGINAL_Y ;
	set(looptxt_pan,SHOW | OVERLAY);
	while(1)
	{
		looptxt_pan->pos_x = cycle(looptxt_pan->pos_x -30 * time_step,-bmap_width(looptxt_pan->bmap),screen_size.x);
		wait(1);
	}
}



Ohterwise, you have to put the numbers manually in the struct as you did at the start.
Posted By: Realspawn

Re: reset function - 06/02/13 16:31

Since i am no coder i want to ask (have to ask)
to learn from it.

My original code works. But is there no easy way to reset/kill
a function so it can be recalled ?

i looked into proc_kill2 that works but does not reset the pictures position:) It should be possible that this function
plays once every time it is called ?

Am i thinking to simple laugh


Posted By: 3run

Re: reset function - 06/02/13 17:12

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.
Posted By: Uhrwerk

Re: reset function - 06/02/13 17:13

Please be more precise: When is this function supposed to end?
Posted By: Anonymous

Re: reset function - 06/02/13 18:08

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);

Posted By: 3run

Re: reset function - 06/02/13 21:16

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
}

Posted By: Anonymous

Re: reset function - 06/02/13 22:03

@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();
}


Posted By: 3run

Re: reset function - 06/02/13 22:31

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
Posted By: Anonymous

Re: reset function - 06/02/13 22:35

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
Posted By: 3run

Re: reset function - 06/02/13 22:38

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
Posted By: Realspawn

Re: reset function - 06/03/13 01:20

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
Posted By: Anonymous

Re: reset function - 06/03/13 01:47

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;
.......
}



© 2024 lite-C Forums