Gamestudio Links
Zorro Links
Newest Posts
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
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, Akow, degenerate_762), 1,430 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
some confusion with handle() #309564
02/10/10 01:15
02/10/10 01:15
Joined: Jan 2007
Posts: 6
Sweden
M
Melvin Offline OP
Newbie
Melvin  Offline OP
Newbie
M

Joined: Jan 2007
Posts: 6
Sweden
Im trying to assign a value to a mineral that is spawned by destroying an asteroid, and iv had a look at the old AUM examples but i just cant get it to work, the code that im using looks like this:

//////////////////
ENTITY* temp_ptr;

var minerals[1000];
var mineral_index = 0;
//////////////////

action green_crystal()
{
minerals[mineral_index] = handle(my);
mineral_index +=1;

///other code//////////

///////////////////////
function moveG(number)
{
temp_ptr =ptr_for_handle(minerals[number])
temp_ptr.y +=50;
}

but when I call it while playing with ex. moveG(1);
nothing happens, I know that the AUM examples are for A6 so the problems are probably because of that, and iv been searching the forums for a few hours without finding anything that can help me.


Would really appreciate some help with this.
Thanks

Re: some confusion with handle() [Re: Melvin] #309567
02/10/10 01:26
02/10/10 01:26
Joined: Feb 2009
Posts: 2,154
Damocles_ Offline
Expert
Damocles_  Offline
Expert

Joined: Feb 2009
Posts: 2,154
C_script
first: temp_ptr =ptr_for_handle(minerals[number])
is missing an " ; "

What this actually does is storing a handle of the mineral
or whatever is running the action to an array.

Later in the moveG function, a pointer is restored from
the array, given an indexnumber.

So the first thing you need to check, is weater the
action gets called (meaning, if an entity is beeing
"stored" in the array.
So watch the minera_index counter, or some other
indicator that this part works.

Then check if the move_g function is beeing called, AFTER the
array was filled with pointers.

If you dont have a nullpointer error, then some entity
is beeing moved (maybe not the mineral you where looking at)

Also the first entry is 0 and not 1
(for 1 you need to have at least two minerals referenced)

Also include some savety features, (like:

if(number>=mineral_index) return;
)

Especially when working with dynamically used arrays and pointers.




Re: some confusion with handle() [Re: Damocles_] #309572
02/10/10 01:42
02/10/10 01:42
Joined: Jan 2007
Posts: 6
Sweden
M
Melvin Offline OP
Newbie
Melvin  Offline OP
Newbie
M

Joined: Jan 2007
Posts: 6
Sweden
Okey, in the code i'm not missing the ; - just missed it when I wrote this laugh

and I checked the index value and it adds one every time a new green mineral is created.

But what I didn't perhaps mention is that i want this to work in C-lite and not C-script as i'm using A7.

I tried calling a few of them after I had 9 minerals (index = 9)
with moveG(3) and moveG(5) but no dice.

But what is a nullpoint error? and how do I know if I got me one of those? laugh

thanks for the help

Last edited by Melvin; 02/10/10 01:42.
Re: some confusion with handle() [Re: Melvin] #309573
02/10/10 01:52
02/10/10 01:52
Joined: Feb 2009
Posts: 2,154
Damocles_ Offline
Expert
Damocles_  Offline
Expert

Joined: Feb 2009
Posts: 2,154
with nullpointer error, i mean, that the
retrieved pointer (the entity) is null,
so basically you got an empty reference back.
This happens when you did not "insert" an entity (handle)
to the array at the given position, or the entiy was destoyed
meanwhile.

But the engine should complain when trying to manipulate this
empty entity then.

Re: some confusion with handle() [Re: Damocles_] #309574
02/10/10 02:07
02/10/10 02:07
Joined: Jan 2007
Posts: 6
Sweden
M
Melvin Offline OP
Newbie
Melvin  Offline OP
Newbie
M

Joined: Jan 2007
Posts: 6
Sweden
Okey, well I don't get any trouble from the engine.

This is all the code that's involved:
(I changed some of the names)
Click to reveal..

////////////////
ENTITY*temp_ptr;

var index = 0;
var entitis[100];
///////////////

action green_crystal_settings ()
{
entitis[index] = handle(me);
index += 1;

var temp_rotation = random(2)-1;
my.skill32 = 1; // identify as mineral
my.skill29 = 1;
set(my, POLYGON);
my.ambient = 100;
my.pan += random(2)-1;
my.tilt += random(2)-1;
my.scale_x = 0.2;
my.scale_y = 0.2;
my.scale_z = 0.2;
my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY | POLYGON | ENABLE_SCAN);
my.event = mineral_hit;
while (me)
{
my.pan += temp_rotation;
my.tilt += temp_rotation;
wait(1);
effect(mineral_green_glow,2,my.x,nullvector);
}
}

function move_entity(numb)
{
temp_ptr = ptr_for_handle(entitis[numb]);
ent_remove (temp_ptr);
}

/////////////////////

After I start it up I wait until I have some minerals and then I press tab and type: move_entity(3)
but none of the little buggers get removed.

Re: some confusion with handle() [Re: Melvin] #309575
02/10/10 02:26
02/10/10 02:26
Joined: Feb 2009
Posts: 2,154
Damocles_ Offline
Expert
Damocles_  Offline
Expert

Joined: Feb 2009
Posts: 2,154
Better us a functioncall using an keypress ingame.
I would not trust that manual debug typing of functions.

(or call automatically is after waiting some time in the mainfunction)

If it still not works, try to call the removal directly
within the entities action using the used indexnumber, then all entities should
be killed right away.

Re: some confusion with handle() [Re: Damocles_] #309576
02/10/10 02:34
02/10/10 02:34
Joined: Jan 2007
Posts: 6
Sweden
M
Melvin Offline OP
Newbie
Melvin  Offline OP
Newbie
M

Joined: Jan 2007
Posts: 6
Sweden
Capital!
It works when I assign it to a key, so I know it works, but still no go when I try to type it in :S any guesses why?

Anyhow from now on ill make sure to only try to call my functions from keys when testing laugh


I tip my hat at you sir!

Re: some confusion with handle() [Re: Melvin] #309578
02/10/10 02:40
02/10/10 02:40
Joined: Feb 2009
Posts: 2,154
Damocles_ Offline
Expert
Damocles_  Offline
Expert

Joined: Feb 2009
Posts: 2,154
no problem.
I never used that debuginput, and would not trust it anyhow.


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