pointer to a panel not working....

Posted By: seneca

pointer to a panel not working.... - 04/20/15 15:46

I have searched, but what I found doesn't seem to work.
all i'm trying to do is access a pointer to a non moving panel created in a for loop.

*******************************************
for(i=0;i<buffercount;i++)
{
if(mytile[i].ktype == 1)
{
//w = i;
water_pan[i] = pan_create("bmap = water.png;", mytile[i].levela);

water_pan[i].pos_x = mytile[i].posxa;
water_pan[i].pos_y = mytile[i].posya;
set(water_pan[i], SHOW);
//w_collisions(water_pan[i],i);
panel_me(i);
//test_show(*myVar);
}
/*
else
{
//w = i;
stone_pan[i] = pan_create("bmap = stone.png;", mytile[i].levela);
stone_pan[i].pos_x = mytile[i].posxa;
stone_pan[i].pos_y = mytile[i].posya;
set(stone_pan[i], SHOW);
}
*/
}
***************************************************
sorry, I can't find the code tags. and I am using a struct, because I thought that the pointer is having a hard time being placed in the while loop.

the error I get is the E1513, everytime, no matter how I phrase it.

below is only 1 of 30 different ways I've tried to access the pointer.

********************************************************
function get_pan(p)
{
var g = p+1;
PANEL* temp_pan_new[100];
temp_pan_new[g] = p;


/*
while (1)
{

if(!play_pan){beep();}
temp_nopposx = g;
if(temp_pan_new[g].pos_x <= player_pan.pos_x)
{
temp_var += .001;
}

wait (1);
}// end while 1
*/
}
****************************************************

I've got other projects where it works fine, but this one...?
I just don't get it.

thanks.
Posted By: Anonymous

Re: pointer to a panel not working.... - 04/20/15 16:47

I got a little lost but two ideas, WAIT(1) after the creation before accessing the panel. Also remember the 0 math so 99 is the last element in the array and 0 the first, do not exceed 99(in your example)
Posted By: 3run

Re: pointer to a panel not working.... - 04/20/15 17:53

Originally Posted By: seneca

for(i=0;i<buffercount;i++)
{
if(mytile[i].ktype == 1)
{
//w = i;
water_pan[i] = pan_create("bmap = water.png;", mytile[i].levela);

water_pan[i].pos_x = mytile[i].posxa;
water_pan[i].pos_y = mytile[i].posya;
set(water_pan[i], SHOW);
//w_collisions(water_pan[i],i);
panel_me(i);
//test_show(*myVar);
}
/*
else
{
//w = i;
stone_pan[i] = pan_create("bmap = stone.png;", mytile[i].levela);
stone_pan[i].pos_x = mytile[i].posxa;
stone_pan[i].pos_y = mytile[i].posya;
set(stone_pan[i], SHOW);
}
*/
}
Here pointer is 'water_pan[i]'. You have somewhere in your code PANEL* water_pan[999]; with probably different numbers in those brackets. To access the pointer use 'i', I would call it ID to make easier for you to understand. So in PANEL* water_pan[999]; you have list of 999 EMPTY panel pointers. In that 'for' loop you create panels from 0 to the amount of buffercount, so you ID range will be from 0 to buffercount (let's say it's 10). So in order to access panel with ID 5 within a list of 10 panels, you have to 'save' it's ID and then check for it, to return the pointer. Let's say you save ID in the 'skill_x', right after you created your panel 'water_pan[i]'.

The following code is not tested, and was made just to give you an idea of how it should work.
Code:
water_pan[i] = pan_create(blahblah);
water_pan[i].skill_x = i;

After this, each of your panel will have it's ID saved, so you can create function like this, to find the panel:
Code:
PANEL* returnWaterPan(id){
     for(i = 0; i < buffercount, i++){
           if(water_pan[i].skill_x == id){
               return(water_pan[i]);
           }
}

Or you can use it directly, if you know the id:
Code:
water_pan[5];



Originally Posted By: seneca

sorry, I can't find the code tags.
Next time when you write your message, press 'Switch To Full Reply Screen' next to 'Submit' and 'Preview Reply', there you'll see '#', press on it and select 'code'. It will create [code*][/code*] (without *), you should write your code between those tags.

Originally Posted By: seneca
the error I get is the E1513, everytime, no matter how I phrase it.

below is only 1 of 30 different ways I've tried to access the pointer.

********************************************************
function get_pan(p)
{
var g = p+1;
PANEL* temp_pan_new[100];
temp_pan_new[g] = p;


/*
while (1)
{

if(!play_pan){beep();}
temp_nopposx = g;
if(temp_pan_new[g].pos_x <= player_pan.pos_x)
{
temp_var += .001;
}

wait (1);
}// end while 1
*/
}
****************************************************

I've got other projects where it works fine, but this one...?
I just don't get it.

thanks.
First of all, what is that '(p)' in the function parameters?? Is that suppose to be a panel name when using that function? Next thing probably causing the empty pointer error is here:
Code:
PANEL* temp_pan_new[100];
temp_pan_new[g] = p;

I'm not sure of what you are trying to do here, but just don't do this. grin It gives me a headache when I try to understand it. Just go with the idea I've wrote above, and you'll be able to access your panels without any problems.


Greets
Posted By: seneca

Re: pointer to a panel not working.... - 04/21/15 13:01

Thanks for your help to the both of you. turn's out it was a timing issue. After I clean up the code to make it less confusing. Thanks again for the great advice.
© 2024 lite-C Forums