Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Sun Jul 17, 2011 4:29 am   

[FEATURE REQUEST] Creating one-way exits in a script
 
Looks like %roomlink isn't able to do this, is there something I'm missing? If it's not possible (yet), I'd like to make this a feature request, it seems like this is the only exit property I'm not able to set without using the GUI...


Last edited by Daern on Mon Jul 18, 2011 8:43 pm; edited 1 time in total
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Sun Jul 17, 2011 5:31 pm   
 
Been trying to simulate this by editing the database directly, but I can't quite get it to work. This is what I have so far:

DISCLAIMER: This is advanced code that could easily corrupt your mapper database. Don't use it unless you know what you're doing.
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="OneWayLink" copy="yes">
    <value><![CDATA[//xdiff > 0, to room is right
//ydiff > 0, to room is below
#LOCAL $dirto
#SQLDB mapper "C:/Program Files/CMUD/Aardwolf.dbm"
$coordfrom = %sql(mapper,%concat("SELECT X,Y FROM ObjectTbl WHERE ObjId=",%roomkey($from)))
$coordto = %sql(mapper,%concat("SELECT X,Y FROM ObjectTbl WHERE ObjId=",%roomkey($to)))
$xdiff = ($coordto.Item("X") - $coordfrom.Item("X"))
$ydiff = ($coordto.Item("Y") - $coordfrom.Item("Y"))
#IF ($xdiff >= 0) {#IF ($ydiff >= 0) {$dirto = "nw"} {$dirto = "sw"}} {#IF ($ydiff >= 0) {$dirto = "ne"} {$dirto = "se"}}
$exitid = %sql(mapper,%concat("SELECT ExitId from ExitTbl WHERE FromID=",%roomkey($from)," AND DirType=",@GetDirType($dir))).Item("ExitId")
#CALL %sql(mapper,%concat("UPDATE ExitTbl SET ToID=",%roomkey($to),",DirToType=",@GetDirType($dirto),",Tested='Y' WHERE ExitId=",$exitid))
#SQLCLOSE mapper]]></value>
    <arglist>$from,$dir,$to</arglist>
  </alias>
  <func name="GetDirType" copy="yes">
    <value>//nw = h, ne = j, sw = k, se = l
//dirtypes: n = 0, ne = 1, e = 2, se = 3, s = 4, sw = 5, w = 6, nw = 7, u = 8, d = 9, other = 10, none = 11
#SWITCH (%1)
  ("n") {#RETURN 0}
  ("ne") {#RETURN 1}
  ("j") {#RETURN 1}
  ("e") {#RETURN 2}
  ("se") {#RETURN 3}
  ("l") {#RETURN 3}
  ("s") {#RETURN 4}
  ("sw") {#RETURN 5}
  ("k") {#RETURN 5}
  ("w") {#RETURN 6}
  ("nw") {#RETURN 7}
  ("h") {#RETURN 7}
  ("u") {#RETURN 8}
  ("d") {#RETURN 9}
  ("other") {#RETURN 10}
  ("none") {#RETURN 11}</value>
  </func>
</cmud>

DISCLAIMER: This is advanced code that could easily corrupt your mapper database. Don't use it unless you know what you're doing.

[EDIT] Looks like this code is working fine now! Shocked But I still have the problem of the map window not redrawing, the changes only show in the room properties window... Changing zones doesn't work, going to Zone -> Refresh doesn't work, what am I missing?
[EDIT 2] Seems the changes aren't permanent either, as soon as I switch to map mode and touch that exit, it reverts Sad
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Jul 18, 2011 6:13 pm   
 
It is possible to use sql to directly affect the map database, but the displayed map will not change. There is no current solution for this; there is no way to force the map to reload the database. If you switch to map mode, it will be using and modifying the loaded version of the map, and will store that version, overwriting the changes you have made. The only way to get the updated display is to close Cmud and restart it. I'm sorry to tell you that you aren't missing anything--there simply isn't a way to do what you want to do, currently.
[edit]In essence, the problem is that the mapper was never intended to be directly modified with sql commands. It was designed to be modified only through the mapper interface, which keeps the display and the database in sync. So, while it is possible to change the map with sql, it is not recommended. I currently do something similar in order to alter the offsets of new up/down exit symbols, so they lie inside the corner of the displayed room, but I run this script in an onExit event, when I close Cmud.[/exit]
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Mon Jul 18, 2011 8:42 pm   
 
Yeah, I'm not worried about not being able to edit the database directly with SQL, that was more of a last ditch effort to make my script work. I'd definitely like to see the ability to make one-way exits in a script in the future though, an addition to %roomlink probably makes most sense. So, treat this thread as a feature request (title updated to reflect this).
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Tue Jul 19, 2011 2:28 am   
 
Perhaps I am misunderstanding the problem about re-drawing the map, but when I make changes to the map database I reload the map so that the changes are reflected. The reload forces the mapper to re-read the database.
_________________
Sic itur ad astra.
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Tue Jul 19, 2011 3:39 am   
 
If by reload you mean close and reopen, I'd rather not have to do that every time I take one step.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Wed Jul 20, 2011 2:23 am   
 
For advanced mapper scripting like this you should probably use the COM-based object API that comes with CMUDPro and zMapper. That's the kind of stuff it was intended for.

Making direct changes to the database is a bad idea because you will have a hard time keeping the internal cache in memory in sync with the physical database.
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Wed Jul 20, 2011 3:25 am   
 
Yeah, I found that out the hard way Sad

I'd rather not get zMapper, since I believe it only reads the old zmud format databases(?) If that's the case, it would be too much hassle to have to convert it back and forth every time I wanted to make a minor change (making a one-way exit every step I take, for example). I would consider upgrading to CMUDPro if it's able to make one way exits in a script, though. Is there anywhere I can read about this COM API? I'm not seeing anything about it in the CMUD or zMapper documentation...
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Wed Jul 20, 2011 10:29 pm   
 
In the zMapper folder there should be a *.HLP help file. In that help file is an appendix on the COM API. That COM API is part of zMapper and CMUDPro. Someday I'll get around to adding it to the online documentation.
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Sat Aug 20, 2011 11:32 pm   
 
Well, I upgraded to CMUDPro today, and I still can't make one-way exits in a script. It looks like a bug in the COM API to me. I tried these two different ways:
Code:
$room = %map.GetRoom(10316)
#CALL $room.SetLink(14056,6,3,"",true) //also tried "true" and 1 for the OneWay boolean value
#CALL $room.Save()

$exit = %map.GetRoom(10316).ExitDir(6)
$exit.ToID = 14056
$exit.DirTo = 3
$exit.OneWay = true //also tried "true" and 1
#CALL $exit.Save()


Both methods just create two-way links. This looks like a bug to me. It should be noted that making one-way links does work with the zMUDMap object's NewLink method, but that creates a true new link, and I want to use the existing stub link, just assigning a direction to it. Am I just missing something obvious?
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Sat Aug 20, 2011 11:38 pm   
 
Heh, apparently I was. It looks like you need to do it in two steps, like this:
Code:
$exit = %map.GetRoom(10316).ExitDir(6)
$exit.ToID = 14056
$exit.DirTo = 3
#CALL $exit.Save()
$exit.OneWay = true
#CALL $exit.Save()


It does look like the first example above is a bug though, probably caused by the same problem. If I had to guess, the zMUDRoom object's SetLink method is just setting the exit properties like my second example does, and it also needs to do it in two steps.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net