Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, mciwjd545, 1 invisible), 787 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: see if a text is still valid [Re: FoxHound] #441756
06/01/14 19:22
06/01/14 19:22
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
So you destroy the panel, set the panels skill_y and then read that skill_y in another function?


Always learn from history, to be sure you make the same mistakes again...
Re: see if a text is still valid [Re: Uhrwerk] #441757
06/01/14 19:35
06/01/14 19:35
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline OP
Expert
FoxHound  Offline OP
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
I set the skill_y to zero and then destroy the text.

Last edited by FoxHound; 06/01/14 19:35.

---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
Re: see if a text is still valid [Re: FoxHound] #441758
06/01/14 19:53
06/01/14 19:53
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Then make sure you wait one frame inbetween... If you want to do it the straigthforward way i've shown you I'm still willing to help. Just post the code that is giving you trouble.


Always learn from history, to be sure you make the same mistakes again...
Re: see if a text is still valid [Re: Uhrwerk] #441763
06/01/14 21:49
06/01/14 21:49
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline OP
Expert
FoxHound  Offline OP
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
What I am making is an editable digit. Right now you can not click on digits in our to manually edit them. So my plan is to make a panel to lay on top of another panel. The new panel is only a button. Put a text in front of that. When the button is pressed inkey is used to edit the string of the text. When we tell that panel to go bye bye it takes the panel and text with it.

Beside the pointer issue, and possible it is the same issue, is that this will only work once. If I try to make more than one of these it will crash when the button is pressed. However if there is just one it works fine. However for the editor I am working on I will probably need 1000.


Here is all the main code

Quote:

//////////////////////////////
// this creates the button panel and text to lay on top of it allowing for editable text
//////////////////////////////
PANEL* create_foxpan(var pos_x,var pos_y,PANEL* mother_panel,BMAP* click_bmap,var* loc_display_var)
{

//////////////////////////////
// we create the panel and give it a button so it can adjust the string and display var
//////////////////////////////
fox_pan = pan_create("",mother_panel.layer + 1);

//////////////////////////////
// we set our position to our mother panel
//////////////////////////////
fox_pan.pos_x = mother_panel.pos_x + pos_x;
fox_pan.pos_y = mother_panel.pos_y + pos_y;

//////////////////////////////
// our bmap is our button
//////////////////////////////
pan_setbutton(fox_pan,0,0,
0,0,click_bmap,click_bmap,click_bmap,NULL,adjust_string,NULL,NULL);


//////////////////////////////
// we create the text and set it's string to that of the var we will display
//////////////////////////////
fox_text = txt_create(1,mother_panel.layer + 2);//1 higher than the butotn panel
str_cpy((fox_text.pstring)[0], "123");
str_for_num((fox_text.pstring)[0],*loc_display_var);

//////////////////////////////
// we set our position to our mother panel
//////////////////////////////
fox_text.pos_x = mother_panel.pos_x + pos_x;
fox_text.pos_y = mother_panel.pos_y + pos_y;

//////////////////////////////
// we record pointers to the panel
//////////////////////////////
fox_pan.skill_x = handle(mother_panel);//loc_display_var;//handle(loc_display_var); //handle(mother_panel);////loc_display_var;
fox_pan.skill_y = handle(fox_text);

//////////////////////////////
// we record pointers to the text
//////////////////////////////
fox_text.skill_x = handle(mother_panel);
fox_text.skill_y = loc_display_var;

//////////////////////////////
// we make the panel and the text visible
//////////////////////////////
set(fox_pan,SHOW);
set(fox_text,SHOW);


//////////////////////////////
// we return our panel pointer
//////////////////////////////
return(fox_pan);
}




//////////////////////////////
// this funciton is called when the button for the fox pan is pushed letting us know we want to change the string and thus the display number
//////////////////////////////
void adjust_string(var button_number,PANEL* panel_pointer)
{

//////////////////////////////
// we declare a string so we can use it to hold the old string
//////////////////////////////
STRING* old_string = "#3";


//////////////////////////////
// we get the pointer for the text we were using
//////////////////////////////
TEXT* temp_text = ptr_for_handle(panel_pointer.skill_y);

//////////////////////////////
// we copy the old string in case we need to put it back
//////////////////////////////
str_cpy(old_string,(temp_text.pstring)[0]);


//////////////////////////////
// we also check to see how we ended the key
//////////////////////////////
var key = inkey((temp_text.pstring)[0]); // wait until [enter] pressed

//////////////////////////////
// we get the var for the number
//////////////////////////////
var new_number = str_to_num((temp_text.pstring)[0]); // vpi == 3.142

//////////////////////////////
// we make sure we entered a number and not a letter
//////////////////////////////
if(new_number == 0)
{


//////////////////////////////
// we copy the original string back to this one
//////////////////////////////
str_cpy((temp_text.pstring)[0],old_string);


//////////////////////////////
// get it right!
//////////////////////////////
printf("must be a number");

}
else
{

//////////////////////////////
// we changed our number so now we need to update or display number
//////////////////////////////
var* loc_temp = temp_text.skill_y;
*loc_temp = new_number;


}




}

//////////////////////////////
// this function checks to see if the var has changed, and if it has we alter the string in the text to match it
//////////////////////////////
void monitor_for_var_change(TEXT** loc_text, var* loc_display_var)
{
//////////////////////////////
// we get the old value of the var
//////////////////////////////
var old_var = *loc_display_var;
// while(ptr_for_handle(handle(loc_text)) != NULL) //while(loc_text == NULL) //while(1)
while(loc_text)
{

//////////////////////////////
// this is for when we are done with the text
//////////////////////////////
if(loc_text.skill_x == 0)
{
sys_exit("");
return;
}

//////////////////////////////
// if our old var was changed then we update the string in the editble text for the fox pan
//////////////////////////////
if(old_var != *loc_display_var)
{
old_var = *loc_display_var;
str_for_num(*(loc_text.pstring)[0],*loc_display_var);
}

wait(1);
}
sys_exit("");
}

void destory_foxpan(PANEL* fox_pan)
{
TEXT* mytext;
mytext = ptr_for_handle(fox_pan.skill_y);

mytext.skill_x = 0;
wait(1);
//////////////////////////////
// we remove the text
//////////////////////////////
ptr_remove(mytext);
mytext = NULL;


//////////////////////////////
// we remove the panel
//////////////////////////////
ptr_remove(fox_pan);

}





Here is how I start up the foxx pans

Quote:

temp_pan_0 = create_foxpan(0,0, mother_pan_show_0, button_to_push_bmap, display_number_0);
temp_text_0 = ptr_for_handle(temp_pan_0.skill_y);
monitor_for_var_change(ptr_for_handle(temp_pan_0.skill_y), display_number_0);


Here is how I destory the fox_pans

Quote:

while(1)
{
if(key_y)
{
destory_foxpan(temp_pan_0);
// return;
while(key_y)wait(1);
}
}


I was planning on making this a user contribution so posting the code is cool.

Last edited by FoxHound; 06/01/14 21:50.

---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
Re: see if a text is still valid [Re: FoxHound] #442314
06/17/14 20:55
06/17/14 20:55
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
FoxHound Offline OP
Expert
FoxHound  Offline OP
Expert

Joined: Jun 2004
Posts: 2,234
Wisconsin USA
I redeveloped the fox pan using a struct and in the end I base if the foxpan needs to be removed by if the mother panel is removed or not. I get the same thing. Only if a handle and ptr_for_handle.

It works but when I put 100 panels with one foxpan on each and nothing else on the screen then the FPS drops to 80.

Once I get this to not be such a FPS eater I will put it in user contributions.

If it matters I use A7 latest.


The setup
Quote:
create_fox_pan(0,0,0,0,mother_pans[a],bmap_create("click_button.png"),values[a]);


The header file
Quote:

#ifndef fox_pan_h
#define fox_pan_h

typedef struct fox_panel {


PANEL* mother_pan;

var* *mother_panel_handle;

PANEL* click_panel;

TEXT* see_string_text;

var* adjustable_var;


var offset_x;
var offset_y;

var text_offset_x;
var text_offset_y;

} fox_panel;




//////////////////////////////
// this is used to create a fox panel and returns the fox panel as a string
//////////////////////////////
fox_panel* create_fox_pan(var pos_x,var pos_y, var text_offset_x,var text_offset_y, PANEL* mother_panel, BMAP* click_bmap,var* loc_display_var);

//////////////////////////////
// this funciton is called when the button for the fox pan is pushed letting us know we want to change the string and thus the display number
//////////////////////////////
void adjust_string_fox_pan(var button_number,PANEL* panel_pointer);

//////////////////////////////
// this keeps track of info on the mother panel and transfer it to the fox panel
//////////////////////////////
void fpan_monitor_function(fox_panel* fp, var* loc_display_var);

//////////////////////////////
// we get rid of the fox panel and everything about ti
//////////////////////////////
void destory_foxpan(fox_panel* fp);

#endif


the main file
Quote:

#ifndef fox_pan_c
#define fox_pan_c


//////////////////////////////
// the fox panel allows for having editable digits on standard panels
// it works by having a mother panel, the main backboard, then creating a panel that only has a button. this button should be invsible or able to look as if it belongs on the backboard
// the function from the button will allow for editing of the text. Pressing enter will set the new number typed in. If letters are typed in it will ignore it.
// If the number is changed outside of the button's function it will be updated.
// if the panel is moved, the button panel and the text will move with it.
//////////////////////////////








//////////////////////////////
// we include our header file
//////////////////////////////
#include <general_functions\fox_pan.h>






//////////////////////////////
// this is used to create a fox panel and returns the fox panel as a string
//////////////////////////////
fox_panel* create_fox_pan(var pos_x,var pos_y, var text_offset_x,var text_offset_y, PANEL* mother_panel, BMAP* click_bmap,var* loc_display_var)
{



//////////////////////////////
// we create the fox panel pointer
//////////////////////////////
fox_panel* temp_fox_panel = malloc(sizeof(fox_panel)); // creates a new SPOT struct at runtime
memset(temp_fox_panel,0,sizeof(fox_panel)); // set the struct content to zero (it's undefined after malloc)


temp_fox_panel.offset_x = pos_x;
temp_fox_panel.offset_y = pos_y;

temp_fox_panel.mother_pan = mother_panel;

// temp_fox_panel.mother_panel_handle = handle(mother_panel);


temp_fox_panel.click_panel = pan_create("",mother_panel.layer + 1);


//////////////////////////////
// we set our position to our mother panel
//////////////////////////////
temp_fox_panel.click_panel.pos_x = mother_panel.pos_x + pos_x;
temp_fox_panel.click_panel.pos_y = mother_panel.pos_y + pos_y;

//////////////////////////////
// our bmap is our button
//////////////////////////////
pan_setbutton(temp_fox_panel.click_panel,0,0,
0,0,click_bmap,click_bmap,click_bmap,NULL,adjust_string_fox_pan,NULL,NULL);


//////////////////////////////
// we create the text and set it's string to that of the var we will display
//////////////////////////////
temp_fox_panel.see_string_text = txt_create(1,mother_panel.layer + 2);//1 higher than the butotn panel

//////////////////////////////
// 10 digits
//////////////////////////////
str_cpy((temp_fox_panel.see_string_text.pstring)[0], "#10");



//////////////////////////////
// we set our position to our mother panel
//////////////////////////////
temp_fox_panel.see_string_text.pos_x = mother_panel.pos_x + text_offset_x;
temp_fox_panel.see_string_text.pos_y = mother_panel.pos_y + text_offset_y;



temp_fox_panel.see_string_text.red = 255;
temp_fox_panel.see_string_text.blue = 0;
temp_fox_panel.see_string_text.green = 0;


temp_fox_panel.adjustable_var = loc_display_var;

//////////////////////////////
// we store the pointer to the fox panel
//////////////////////////////
temp_fox_panel.click_panel.skill_x = handle(&temp_fox_panel);


//////////////////////////////
// we make the panel and the text visible
//////////////////////////////
set(temp_fox_panel.click_panel,SHOW);
set(temp_fox_panel.see_string_text,SHOW);

//////////////////////////////
// we now make the fox panel behave with the mother panel
//////////////////////////////
fpan_monitor_function(temp_fox_panel, *loc_display_var);

//////////////////////////////
// we return our panel pointer
//////////////////////////////
return(temp_fox_panel);





}






//////////////////////////////
// this funciton is called when the button for the fox pan is pushed letting us know we want to change the string and thus the display number
//////////////////////////////
void adjust_string_fox_pan(var button_number,PANEL* panel_pointer)
{

//////////////////////////////
// we declare a string so we can use it to hold the old string
//////////////////////////////
STRING* old_string = "#3";


fox_panel* temp_fp = handle(panel_pointer.skill_x);



//////////////////////////////
// we get the pointer for the text we were using
//////////////////////////////
TEXT* temp_text = temp_fp.see_string_text;//ptr_for_handle(panel_pointer.skill_y);


//////////////////////////////
// we copy the old string in case we need to put it back
//////////////////////////////
str_cpy(old_string,(temp_text.pstring)[0]);


//////////////////////////////
// we also check to see how we ended the key
//////////////////////////////
var key = inkey((temp_text.pstring)[0]); // wait until [enter] pressed

//////////////////////////////
// we get the var for the number
//////////////////////////////
var new_number = str_to_num((temp_text.pstring)[0]); // vpi == 3.142

//////////////////////////////
// we make sure we entered a number and not a letter
//////////////////////////////
if(new_number == 0)
{


//////////////////////////////
// we copy the original string back to this one
//////////////////////////////
str_cpy((temp_text.pstring)[0],old_string);


//////////////////////////////
// get it right!
//////////////////////////////
printf("must be a number");

}
else
{

//////////////////////////////
// we changed our number so now we need to update or display number
//////////////////////////////
*temp_fp.adjustable_var = new_number;

}

}



//////////////////////////////
// this keeps track of info on the mother panel and transfer it to the fox panel
//////////////////////////////
void fpan_monitor_function(fox_panel* fp, var* loc_display_var)
{

//////////////////////////////
// we get the old value of the var
//////////////////////////////
var old_var = *loc_display_var;


//////////////////////////////
// as long as the mother panel is good we are good
//////////////////////////////
while(ptr_for_handle(handle(fp.mother_pan)))
{


//////////////////////////////
// for testing purposes
//////////////////////////////
// loc_mother_pan.pos_x = random(800);
// loc_mother_pan.pos_y = random(800);


//////////////////////////////
// we keep our position the same
//////////////////////////////
fp.click_panel.pos_x = fp.mother_pan.pos_x + fp.offset_x;
fp.click_panel.pos_y = fp.mother_pan.pos_y + fp.offset_y;
//////////////////////////////
// now the text panel
//////////////////////////////
fp.see_string_text.pos_x = fp.mother_pan.pos_x + fp.text_offset_x;
fp.see_string_text.pos_y = fp.mother_pan.pos_y + fp.text_offset_y;


//////////////////////////////
// if the mother panel is invsible then so are we
//////////////////////////////
if(is(fp.mother_pan,SHOW))
{
set(fp.click_panel,SHOW);
set(fp.see_string_text,SHOW);
}
else
{
reset(fp.click_panel,SHOW);
reset(fp.see_string_text,SHOW);
}




//////////////////////////////
// if our old var was changed then we update the string in the editble text for the fox pan
//////////////////////////////
if(old_var != *loc_display_var)
{
old_var = *loc_display_var;
str_for_num( (fp.see_string_text.pstring)[0],old_var);
}


wait(1);
}

destory_foxpan(fp);



}





//////////////////////////////
// we no longer need the fox pan so we get rid of it
//////////////////////////////
void destory_foxpan(fox_panel* fp)
{


//////////////////////////////
// we remove the text
//////////////////////////////
ptr_remove(fp.see_string_text);
fp.see_string_text = NULL;


//////////////////////////////
// we remove the panel
//////////////////////////////
ptr_remove(fp.click_panel);
fp.click_panel = NULL;

//////////////////////////////
// now we get rid of the fox panel itself
//////////////////////////////
free(fp);

}

#endif


---------------------
There is no signature here.


QUIT LOOKING FOR ONE!
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