|
|
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
Expert
|
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.
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
Senior Expert
|
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
Serious User
|
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 
Last edited by Widi; 09/17/10 11:53.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|