3 registered members (Ayumi, Akow, AndrewAMD),
1,505
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
Expert
|
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
|
Malice
Unregistered
|
Malice
Unregistered
|
Really? function loops once and is recursive
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.
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 ...
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
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
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):
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
}
|
|
|
Re: reset function
[Re: 3run]
#423670
06/02/13 22:03
06/02/13 22:03
|
Malice
Unregistered
|
Malice
Unregistered
|
@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?
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
Senior Expert
|
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 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
|
|
|
Re: reset function
[Re: 3run]
#423672
06/02/13 22:35
06/02/13 22:35
|
Malice
Unregistered
|
Malice
Unregistered
|
I don't really know, what he is trying to archive
Yeah like Uhrwerk said the other day... 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
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Yeah like Uhrwerk said the other day... Totally random guessing is a lot more fun That made me ROFL Realspawn@ if you need a scrolling (looping) text, take a look at this one: Scrolling Text Request Greets
|
|
|
Re: reset function
[Re: 3run]
#423674
06/03/13 01:20
06/03/13 01:20
|
Joined: Jul 2001
Posts: 4,801 netherlands
Realspawn
OP
Expert
|
OP
Expert
Joined: Jul 2001
Posts: 4,801
netherlands
|
wow grinnn a lot of response 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 Hope this cleares things up. Its 03:20 here so i get some sleep and will tinker tomorrow some more
|
|
|
Re: reset function
[Re: Realspawn]
#423675
06/03/13 01:47
06/03/13 01:47
|
Malice
Unregistered
|
Malice
Unregistered
|
I would think something like this... I still don't like the idea of using proc_kill this way.
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.
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..
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.
|
|
|
|