Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Move() set x and y (https://forums.graalonline.com/forums/showthread.php?t=134269319)

blackbeltben 06-16-2014 11:23 PM

Move() set x and y
 
I have been messing around with alternate ways to move my "bullet."

I have been using the move() function a little bit but I cannot get it accurate.

PHP Code:

function onCreated(){
 
setImg("blackbeltben_bullet.png");
 
setShape(13232);
 
onTimeOut();
 
scheduleEvent(5"onDelete");
 
//the new x and y were set in the putNPC
 
this.newx this.newx
 this
.newy this.newy
 
//in this case, the newx and newy were set as the curret mousex and mousey at the point of the creation
}

function 
onTimeOut(){
 
setTimer(0.1);
 
//Here I'd like it to move to this.newx, this.newy 
}

function 
onDelete(){
 
destroy();



If I am using a move(), I should not be putting it in a timeOut. But I'm assuming that there is no way to set a specific x and y with move().
With that being said, I'm guessing I have to calculate how much the x and y need to be increased/decreased... Which I am not sure how to do..


straight to the point
I want my NPC to move directly to this.newx, this.newy at a speed of 0.5;

fowlplay4 06-16-2014 11:56 PM

PHP Code:

function onCreated() {
  
setImg("blackbeltben_bullet.png"); 
  
setShape(13232); 
  
moveBullet();
}

function 
movebullet() {
  
temp.dx this.newx this.x// delta = final position - initial position
  
temp.dy this.newy this.y;
  
temp.dist vectordist({this.xthis.y0}, {this.newxthis.newy0}); 
  
temp.speed 0.5;
  
temp.time temp.dist temp.speed;
  
move(temp.dxtemp.dytemp.time0);
  
setTimer(temp.time);
}

function 
onTimeout() {
  
destroy();



blackbeltben 06-17-2014 12:23 AM

Quote:

Originally Posted by fowlplay4 (Post 1728135)
PHP Code:

function onCreated() {
  
setImg("blackbeltben_bullet.png"); 
  
setShape(13232); 
  
moveBullet();
}

function 
movebullet() {
  
temp.dx this.newx this.x// delta = final position - initial position
  
temp.dy this.newy this.y;
  
temp.dist vectordist({this.xthis.y0}, {this.newxthis.newy0}); 
  
temp.speed 0.5;
  
temp.time temp.dist temp.speed;
  
move(temp.dxtemp.dytemp.time0);
  
setTimer(temp.time);
}

function 
onTimeout() {
  
destroy();




Please forgive me if this sounds like a dumb question.. But what is the point of putting temp? Couldn't you just put this.dy, this.dist... etc

Keep in mind I don't know much about "temp" stuff

fowlplay4 06-17-2014 02:00 AM

Quote:

Originally Posted by blackbeltben (Post 1728136)
Please forgive me if this sounds like a dumb question.. But what is the point of putting temp? Couldn't you just put this.dy, this.dist... etc

Keep in mind I don't know much about "temp" stuff

Well it's for temporary values/variables. When you use this. or no prefix at all those variables stay in memory with the npc / globally.

Using temp also guarantees the variable will be empty/0 and won't conflict with other parts of your script.

Quick example:

PHP Code:


// output:
// 0
// 245
// 123

function onCreated() {
  
temp.123;
  
test();
  echo(
temp.a);
}

function 
test() {
  echo(
temp.0);
  
temp.245;
  echo(
temp.a);



Torankusu 06-17-2014 08:06 AM

^^ what he said, simplified, temp variables (values) exist primarily within the function they are specified (unless otherwise passed and named).

"this" variables are accessible throughout the script.
"temp" variables are accessible through a function but discarded and not maintained in memory.
they can still be passed to another function.


All times are GMT +2. The time now is 04:00 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.