Light Switch

Login to reply  Page: « < 1 of 1 > »
28 Sep 2009 - 17:031906
Light Switch
I have a script that sets a global when a player pushes a button. The room script I've been working on checks the global and was going to change the rooms from darkened to lit in which it is assigned. Is there not a way to do that? I haven't had any luck in finding any variable/commands to do anything like it. I could hack around it, like changing the exits to teleport to lit versions of the rooms or casting infravision on them, but it seems... kludgy.


28 Sep 2009 - 19:561907
Well, you were right. No easy way to do it, without kludging.

so I made a small patch for your dg_variables.c file, allowing you to write:
%room.toggleflag(DARK)%

         } else
           snprintf(str, slen, "0");
       }
+      else if (!str_cmp(field, "toggleflag")) {
+        if (subfield && *subfield) {
+          room_rnum thisroom = real_room(r->number);
+          int i, item=-1;
+          for (i=0; i<NUM_ROOM_FLAGS && item < 0; i++)
+            if (!strcmp(subfield, room_bits[i]))
+              item = i;
+
+          // disallow some internal flags.
+          if (item < 0 || item == ROOM_DEATH || item == ROOM_GODROOM || 
+              item == ROOM_HOUSE || item == ROOM_HOUSE_CRASH || item == ROOM_ATRIUM ||
+              item == ROOM_OLC || item == ROOM_BFS_MARK || item == ROOM_WORLDMAP) {
+            strcpy(str, "");
+            script_log("Trigger: %s, VNum %d, type: %d. room.toggleflag unknown or bad flag: %s",
+                       GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig), type, subfield);
+          } else {
+            TOGGLE_BIT_AR(ROOM_FLAGS(thisroom), item);
+            if (IS_SET_AR(ROOM_FLAGS(thisroom), item))
+              snprintf(str, slen, "1");
+            else
+              snprintf(str, slen, "0");
+          }
+        }
+        else {
+          strcpy(str, "");
+          script_log("Trigger: %s, VNum %d, type: %d. room.toggleflag needs subfield",
+                         GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig), type);
+        }
+      }
       else if (!str_cmp(field, "north")) {
         if (R_EXIT(r, NORTH)) {
           if (subfield && *subfield) {


__________________
You know who I am.
29 Sep 2009 - 18:251908
Quote welcor:
Well, you were right. No easy way to do it, without kludging.


Holy crap, that's awesome. Thanks a ton! I'll give it a go tonight and see how it works out.


27 Oct 2009 - 02:201992
I took a hiatus and just realized that I never posted back on this. I tested it with my script that shows messages to verify my remote var's, but it seems the toggle is bugged. I hit a bug (dg_variables.c:1363: warning: statement with no effect) after verifying the code and recompiling. The line in question is
 for (i=0; i<NUM_ROOM_FLAGS && item < 0; i++)
I took a look into it, but I'm still a white belt in my c-fu yet and the solution completely eludes me. Thanks again for coming up with the code,


27 Oct 2009 - 06:231993
Weird - that code should work. It's browser code, though, so I might have forgotten something. I'll get back to you when I get the time to actually test my code (which should be later today)


__________________
You know who I am.

Last edited by welcor (27 Oct 2009 - 06:24)
03 Jan 2010 - 22:192212
Welcor,

Hate to res an old thread, but I think this functionality may be beneficial for some others. I dropped the code into stock 3.60 code and it worked! The only exception is that it's %self.toggleflag(DARK)% when I assigned it to a room script. Awesome work!



Last edited by sedition (03 Jan 2010 - 22:45)
Login to reply  Page: « < 1 of 1 > »