|
Development Forum |
 |
|  Sanely Insane
RisenAngel
     Manager

|
7/20/2013 | |
For my next piece of development, I decided to make a warp portal that serves as a doorway, mostly to provide creatures with a portal that provides them with the proper stims and actually transports them.
inst
*How many portals are already in the world?
doif totl 3 9 18700 = 0
*If there aren't any, create two portals
setv va00 2
else
*Otherwise, create 1 portal
setv va00 1
endi
reps va00
*Offline portals have the exactly same attributes as their online counterparts
new: simp 3 9 18700 "ds portals" 39 0 400
attr 199
clac 2
elas 0
accg 5
aero 10
perm 60
puhl -1 95 110
*ov00 = is it open or closed?
setv ov00 0
*ov01 = is it functioning (Is blue swirl present?)
setv ov01 0
*ov02 = portal to warp to
seta ov02 null
*ov03 = was portal just used?
setv ov03 0
*Dump the portals into the inventory
seta va01 targ
enum 1 2 11
spas targ va01
doif ov00 = 0 and clac = 0
mesg writ targ 0
endi
next
repe
*Deactivate - or rather, open/close the portal
scrp 3 9 18700 0
*Remove interruptions
lock
*If you're closed....
doif ov00 = 0
*Lock it down in place
attr 197
*Animate, make a noise, and open up
anim [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19]
sndc "por1"
over
*Start timer, let creatures push you, and mark yourself as "open"
tick 1
bhvr 1
setv ov00 1
*Otherwise, do the inverse
else
*If you've got a blue swirl, turn that off first
doif ov01 = 1
*Fade out
anim [23 23 22 21 20 19]
setv ov01 0
fade
over
endi
sndc "por2"
*Turn off tick, don't let creatures push you, and mark yourself as closed
tick 0
bhvr 0
setv ov00 0
anim [18 17 16 15 14 13 12 11 10 9 8 6 7 5 4 3 2 1 0]
over
*Become carriable again
attr 199
endi
endm
*Portal push
scrp 3 9 18700 1
*Remove interruptions
lock
*Did a creature activate this?
doif crea from = 1
*Before anything else, make sure you're open
doif ov01 = 1
*Can you be used?
doif ov03 = 0
*Make a noise
sndc "wr_e"
*Tell creature to wait
stim writ from 75 1
*Get its identification
seta va99 from
*Loop until you find another open portal that isn't you
loop
rtar 3 9 18700
doif targ <> null
doif targ <> ownr
doif ov00 <> 0 and ov01 <> 0
seta mv02 targ
endi
endi
endi
targ ownr
untl ov02 <> null
*Get fellow portal's position
targ ov02
setv va00 posx
setv va01 posy
addv va01 50
targ va99
*Move it, move it!
doif targ <> null and movs = 0
mvsf va00 va01
*Target the other portal, make it make a noise, and make it so it can't be used again for a short while
targ mv02
setv ov03 1
sndc "wr_a"
*Simulate actual warp jump
targ va99
aslp 0
pose 59
*Tell creature it warped and used a metaroom door
stim writ targ 27 1
stim writ targ 95 1
wait 30
endi
targ ownr
else
*If it's not open, tell the creature that it's wasting its time
stim writ from 0 1
endi
endi
endi
endm
*Portal timer
scrp 3 9 18700 9
*Check for other open portals in the world
setv va00 0
enum 3 9 18700
doif targ <> null
doif targ <> ownr
doif ov00 <> 0
addv va00 1
endi
endi
endi
next
*If there is another open portal in the world and you're off, turn on
doif va00 >= 1 and ov01 = 0
*Start humming
sndl "humm"
anim [20 21 22 23]
over
*Mark yourself as open
setv ov01 1
anim [24 25 26 27 28 29 30 31 32 33 34 35 36 37 255]
*If you're the only open portal in the world, turn off
elif va00 = 0 and ov01 = 1
*Fade out
anim [23 23 22 21 20 19]
setv ov01 0
fade
over
endi
*If you've just been used, wait a bit before turning back on
doif ov03 = 1
wait 30
setv ov03 0
endi
endm
*Portal exception - this is a failsafe
scrp 3 9 18700 255
*Unfortunately, there's not a lot to put here
endm
*Removal
rscr
enum 3 9 18700
kill targ
next
scrx 3 9 18700 0
scrx 3 9 18700 1
scrx 3 9 18700 9
scrx 3 9 18700 255 |
The above code is working more or less perfectly, but there's a problem with it that's baffling me. Said problem appears to be with this bit:
loop
rtar 3 9 18700
doif targ <> null
doif targ <> ownr
doif ov00 <> 0 and ov01 <> 0
seta mv02 targ
endi
endi
endi
targ ownr
untl ov02 <> null |
What this code is supposed to do is select an open warp portal to which to send a creature. However, for whatever reason, sometimes the code selects a closed warp portal and acts like it's open, which tends to confuse the creature who just used the portal.
I've looked the code over multiple times, and can't seem to find a good reason as to why this is. Perhaps someone else with sharper eyes can look it over and pinpoint what the heck's going on here?
As a note, you should be able to copy-paste this code into the CAOs Tool and inject it without problems - the agent just uses sprites already present in DS.
~ The Realm ~
Risen Angel's Creatures Blog
|
 Peppery One
Papriko
    
|
7/20/2013 | |
Perhaps it selects the portal while it tries to close? Just in the right time, so that during the DOIF check it is open, but when the actual teleport occurs, it is closed? Unlikely, but possible. In case it's that, try putting the code inside the loop into an INST.
loop
inst
rtar 3 9 18700
doif targ <> null
doif targ <> ownr
doif ov00 <> 0 and ov01 <> 0
seta mv02 targ
endi
endi
endi
targ ownr
slow
untl ov02 <> null |
Also, sure you wanna keep the overall principle like that? It may be caught it some weird endless loop when no suiting second portal is found...
Lets play plants! Photosynthesis... Photosynthesis... Photosynthesis... |

Malkin
     Manager

|
7/20/2013 | |
Will it work with swimming creatures?
My TCR Norns |
 Sanely Insane
RisenAngel
     Manager

|
7/21/2013 | |
@Papriko: The problem here is the closed portals creatures are getting warped to are completely closed, not in the process of closing. Both open/closed flags are set to closed, yet somehow the code is thinking otherwise.
I threw the inst/slow flag in there anyway to see if it helped, and it didn't work.
Granted, I've only had the problem show up three times with this iteration of the code, but I'm baffled as to why it's happening at all.
As for the loop: the code only gets to that point if there's another open portal with a blue swirl in the world; creatures can't use it otherwise. That said, it's probably possible to set off an infinite loop, but you'd actually have to try to trigger it.
@Malkin: At the moment, no. Swimming creatures can push the portal, but it won't move them. I may include the functionality once I've squashed the closed portals bug, though I'm also planning on making a portal that's more thematically fitting for underwater worlds and might just save it for that one.
~ The Realm ~
Risen Angel's Creatures Blog
|

Malkin
     Manager

|
7/22/2013 | |
With the 'wait a while' feature of the portals, what does a norn feel if they push the portal while the portal is 'waiting a while' - do they get a shot of disappointment?
My TCR Norns |
 Sanely Insane
RisenAngel
     Manager

|
7/23/2013 | 1 |
They just don't feel anything. I felt this was the best way to handle it without either making the portals cause EE syndrome (which happens sometimes with the elevines, for example) while also preventing instinct screw (which can happen with the interporters, for example).
~ The Realm ~
Risen Angel's Creatures Blog
|
|