Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-16-2014, 11:23 PM
blackbeltben blackbeltben is offline
Registered User
Join Date: Aug 2011
Posts: 83
blackbeltben is on a distinguished road
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;
Reply With Quote
  #2  
Old 06-16-2014, 11:56 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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();

__________________
Quote:
Reply With Quote
  #3  
Old 06-17-2014, 12:23 AM
blackbeltben blackbeltben is offline
Registered User
Join Date: Aug 2011
Posts: 83
blackbeltben is on a distinguished road
Quote:
Originally Posted by fowlplay4 View Post
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
Reply With Quote
  #4  
Old 06-17-2014, 02:00 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by blackbeltben View Post
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);

__________________
Quote:
Reply With Quote
  #5  
Old 06-17-2014, 08:06 AM
Torankusu Torankusu is offline
Elite Member
Torankusu's Avatar
Join Date: Jun 2001
Posts: 10,065
Torankusu has a spectacular aura aboutTorankusu has a spectacular aura about
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.
__________________
Quote:
Originally posted by Spark910
Think befreo you type.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:12 AM.


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