Gamestudio Links
Zorro Links
Newest Posts
zorro license, IB connection
by miwok. 12/06/23 16:32
Newbie Questions
by fairtrader. 12/06/23 11:29
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
6 registered members (miwok, AndrewAMD, TipmyPip, 3run, Quad, 1 invisible), 645 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
something doing wrong whit variables declaration #341487
09/17/10 11:25
09/17/10 11:25
Joined: Sep 2010
Posts: 82
P
peteredlin Offline OP
Junior Member
peteredlin  Offline OP
Junior Member
P

Joined: Sep 2010
Posts: 82
Hello i am new to gamestudio and wrote my first tiny program, i no i am doing something wrong but dont know how to fix it....

here is the code:

///////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>

///////////////////////////////////////////////////////////////
ENTITY*cube;
var x,y,z;

function lift()
{
cube.x=cube.x+1;

}





function main()
{
level_load("small.hmp");
cube = ent_create("mymesh.mdl",vector(0,0,0),lift);

}

Thanks in advance...

Re: something doing wrong whit variables declaration [Re: peteredlin] #341489
09/17/10 11:45
09/17/10 11:45
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Welcome aboard, and simple mistake. Im sure we've all done this at some stage.

Your function 'lift' doesnt contain a loop, so it only gets run once and then terminates.

It needs to contain a loop to 'keep going', like so.
Code:
function lift()
{
   while(1)
   {
      cube.x = cube.x + 0.001;
      wait(1);
   }
}


note:: I changed your value from 1.0 to 0.001 so you can see it happen.
If it is left at 1.0, the it will disappear from view too quickly to be seen...

And the "wait(1);" is CRITICAL in a loop.
It gives the engine time to do inportant stuff, like drawing the screen updates...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: something doing wrong whit variables declaration [Re: peteredlin] #341490
09/17/10 11:52
09/17/10 11:52
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Hi and welcome!
What's your problem or what is your error message, if any?

I think there could be a problem:
cube = ent_create("mymesh.mdl",vector(0,0,0),lift);
When you call ent_create, the function "lift" will be started immediately. As a result, the pointer "cube" will be empty what results in an error message.
Then, after executing the bold part, in particular the "lift" function, the left part of the code ("cube = ...") will be executed.

Solution:

function lift() {
cube = me;
cube.x=cube.x+1;
}

function main() {
level_load("small.hmp");
ent_create("mymesh.mdl",vector(0,0,0),lift);
}

Then there's another mistake which is, as you've already guessed, the declaration of var x,y,z; in combination with cube.x.
x,y,z are predefined in the struct ENTITY, that means that you can access the x,y,z components of each entity without the need to declare the variables.

Be aware that your function lift only runs one frame, there won't be any movement at all. If you wish to have movement, you will need a while(1)...wait(1) loop:

function lift() {
cube = me; // now are my,me and cube equivalent inside this function
while(1) {
my.x=my.x+1;
wait(1);
}
}

You should make the movement independent from various framerates (key word: time_step).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: something doing wrong whit variables declaration [Re: EvilSOB] #341491
09/17/10 11:52
09/17/10 11:52
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
...and you don`t have to declare x,y,z, because this are already included by the entity (cube.x) for his position.

EDIT: Superku was faster wink

Last edited by Widi; 09/17/10 11:53.
Re: something doing wrong whit variables declaration [Re: EvilSOB] #341492
09/17/10 11:54
09/17/10 11:54
Joined: Sep 2010
Posts: 82
P
peteredlin Offline OP
Junior Member
peteredlin  Offline OP
Junior Member
P

Joined: Sep 2010
Posts: 82
Hello thanks for youre reply, but i changed the code and now i get an 1513 error code.It has something to do with the cube.x variable.(not being declared or such..)

Maby you can help me out again..

Re: something doing wrong whit variables declaration [Re: peteredlin] #341494
09/17/10 11:58
09/17/10 11:58
Joined: Sep 2010
Posts: 82
P
peteredlin Offline OP
Junior Member
peteredlin  Offline OP
Junior Member
P

Joined: Sep 2010
Posts: 82
Ok now it works ,a great thanks to you people


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