ID:177433
 
proc/firePhaser(mob/M as mob)
if(M in view(5,src))
M << ""

ok so looking through demos and useing the help subject has gotten me this far. I dont know why I am having trouble with this code it seems like this would be simple.
all I want is for an npc and a player to start this loop when they get within 5 spaces of each other.
please someone help
Treasurecat wrote:
proc/firePhaser(mob/M as mob)
if(M in view(5,src))
M << ""

ok so looking through demos and useing the help subject has gotten me this far. I dont know why I am having trouble with this code it seems like this would be simple.
all I want is for an npc and a player to start this loop when they get within 5 spaces of each other.
please someone help

There's no loop there, so calling it a loop is rather inaccurate. I think to do this you'd need to set up some kind of proc looping for each mob when it's first created--possibly only player mobs.

Lummox JR
In response to Lummox JR
mob/romulan

icon = 'person.dmi'
icon_state = "romulan"
cl = -1
hp = 5




proc/firePhaser(mob/M as mob)
if(M in view(5,src))
M << ""

this should be simple. if mob/M moves in to view of mob/romulan then M << "" else void. also mob/romulan is a moving object so if it moves into view of mob/M then the function should be true.

wouldnt this be the way to write that out? I wrote a similar proc() and it worked isDead() and this looks like how the demos work this. what am I missing
In response to Treasurecat
Treasurecat wrote:
proc/firePhaser(mob/M as mob)
if(M in view(5,src))
M << ""

this should be simple. if mob/M moves in to view of mob/romulan then M << "" else void. also mob/romulan is a moving object so if it moves into view of mob/M then the function should be true.

Why would this happen if M moves into view? You've shown nothing that's calling the proc; this code will never be executed because nothing calls it. There's no loop being run at all. When the proc is called, and only when it is called, it will check just once each time to see if M is in view.

wouldnt this be the way to write that out? I wrote a similar proc() and it worked isDead() and this looks like how the demos work this. what am I missing

You're missing putting all this in a loop (Deadron's event loop system is a good place to look). You can't just write a proc and assume something, sometime, is going to call it unless you actually write in the code to call it. You can't assume it's going to run over and over again unless you tell it to do just that.

Lummox JR
In response to Lummox JR
ok how do I activate this proc when they are withing view. I thought it was with the (argument) area
In response to Treasurecat
mob
romulan
proc
Scan()
if(locate(M in oview(5))
M << ""
spawn(5) Scan()
New() //called when the mob is created
spawn() Scan()
In response to Garthor
Garthor wrote:
mob
romulan
proc
Scan()
if(locate(M in oview(5))
M << ""
spawn(5) Scan()
New() //called when the mob is created
spawn() Scan()

thanks I tried this in various ways but it does not imput the text on the screen when the player moves near the romulan wich is what im trying to get done. I was not aware of the scan() though maybe that will be my answere I dont understand what the spawn() was for I tried this code both with and without neither worked if you have anyother ideas on how I can get this done please help.
thanks
In response to Treasurecat
Treasurecat wrote:
ok how do I activate this proc when they are withing view. I thought it was with the (argument) area

No, not at all.
With a verb--not a regular proc--you can tell the client to only pick from mobs in view() or range() (and more). But this doesn't mean that the verb is run as soon as there are mobs to choose from; it means that when the player uses that verb, that mob will be one of the available choices.

Nothing will loop unless you tell it to loop.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Treasurecat wrote:
ok how do I activate this proc when they are withing view. I thought it was with the (argument) area

No, not at all.
With a verb--not a regular proc--you can tell the client to only pick from mobs in view() or range() (and more). But this doesn't mean that the verb is run as soon as there are mobs to choose from; it means that when the player uses that verb, that mob will be one of the available choices.

Nothing will loop unless you tell it to loop.

Lummox JR

ok how do I activate this proc when they are within view?
In response to Treasurecat
Treasurecat wrote:
ok how do I activate this proc when they are within view?

You need a loop running that will periodically check to see if a target is in view. This is called polling; it's the programming equivalent of saying "Are we there yet?" over and over.

An alternative is to run a check on a mob whenever it moves. However, this probably isn't as useful to you, because chances are you'll want some kind of AI loop for your ships anyway; the AI loop, that handles how and where to move ships, should also be responsible for decisions to fire.

Lummox JR
In response to Lummox JR
how do I run a check on my mob/romulan whenever it moves?
In response to Treasurecat
Scan() is a player defined proc, much like your phaser firing proc. As for the Spawn() statements; fist, look up Spawn in the help files. Seriously, look it up before reading on. If you figure it out, don't bother with any more of this post.

In case you don't understand what's being said there (happens often enough to me), here's the run down.
spawn(tenths of seconds) //self explanatory, it takes an
//argument as a number which
//represents tenths of seconds (10 = 1 second)


spawn(n) waits for a number of 1/10 seconds, then executes the statement after it (usually indented)

Now for a practical example:
proc/ThreeSeconds()
spawn(30)
world<<"It's been three seconds!"
ThreeSeconds()
world
New()
..()
ThreeSeconds()


First, we override the New() proc of the world and tell it to call the ThreeSeconds() proc. That means that whenever the game starts, as in the game world is created (such as hosting or running it), it will call the proc, but only once. The proc itself, ThreeSeconds, has the statment: spawn(30). It waits 300 tenths of a second (3 seconds) and executes the statement(s) under it (world<<"It's been three seconds!") and calls itself (thereby creating the loop). So, every 3 seconds, "It's been three seconds!" should appear in the text window.

Hope that helped some.
In response to sapphiremagus
spawn() is used to wait a while, then do a piece of code, without interrupting the rest of your code. Everything MUST be indented. Also, when doing a loop, you want to use spawn() LOOP() instead of just LOOP(), unless if you return it later. Also, 300 / 10 = 30, not 3.