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
zilch
Newbie


Joined: 07 Feb 2020
Posts: 8

PostPosted: Thu Jan 26, 2023 10:29 pm   

Scripting Question - Gauges
 
Accidentally posted this in beta forum so I'll repost here.

Setting up an affects bar and having some issues. The code works fine, but when the gauges are refreshed there is a 1/4 second freeze. Is this from UI refreshing gauges or something in my code?? Any suggestions appreciated!

(edit)

Pretty sure you'll need more info than that.

The script fires off a MSDP trigger for AFFECTS.
Affect string comes raw data with bells and whistles so I format those out while converting to a string list.
The trigger fires about every second or two.

Code:

#LOCAL $newAffects
// Format newAffects string list from data recieved from mud
$new_data = %replace(%replace(%1, %char(7)%char(7) , "|"), %char(7), "")
// Compile a database record of formated newAffects
#FORALL ($new_data) {
  $affect_data = %replace(%i, "," , " ")
  $rounds = %word($affect_data, %numwords($affect_data))
  $affect_data = %remove($rounds, $affect_data)
  $affect = %replace(%trim($affect_data), " ", "_")
  #ADDKEY $newAffects $affect $rounds
  // If its a new affect add it to @affects
  #IF (!%iskey(@affects, $affect)) {
    #ADDKEY affects $affect $rounds
  }
  // If we dont have a gauge for this spell then create one
  #IF (%class(btn_affect_$affect) < 0) {
    #BUTTON btn_affect_$affect %concat(%replace(%proper($affect), "_", " "), " (@affects.", $affect, ")") {} {} {} {@affects.$affect} {} {} {Size} {144} {23} {} {1} {1} {} {} {Gauge|Lime|red|1350|100} {-19} {Bar_Affects} {Explore|Inset} {} {} {3}
  } { // If we have a gauge and its off, toggle it on
    #IF (!%trigger(btn_affect_$affect)) {#T+ btn_affect_$affect}
  }
}
// Loop through affects to remove expired spells and update existing ones
#LOOPDB (@affects) {
  //If its not in the newAffects remove it and turn the gauge off
  #IF (!%iskey($newAffects, %key)) {
    #T- btn_affect_%key
    #DELKEY affects %key
  } {
    affects.%key = $newAffects.%key
  }
}
Reply with quote
zilch
Newbie


Joined: 07 Feb 2020
Posts: 8

PostPosted: Fri Jan 27, 2023 12:17 pm   Think I fixed it
 
When I added the #SORT affects it started working correctly

Also moved some out of the #LOOPDB so that it updates everything at once

Code:

#LOCAL $newAffects
// Format newAffects data recieved from mud
$new_data = %replace(%replace(%1, %char(7)%char(7) , "|"), %char(7), "")
// Compile a database record of formated newAffects
#SORT affects
#FORALL ($new_data) {
  $affect_data = %replace(%i, "," , " ")
  $rounds = %word($affect_data, %numwords($affect_data))
  $affect_data = %remove($rounds, $affect_data)
  $affect = %replace(%trim($affect_data), " ", "_")
  #ADDKEY $newAffects $affect $rounds
  // If its a new affect add it to @affects
  #IF (!%iskey(@affects, $affect)) {
    #ADDKEY affects $affect $rounds
  }
  // If we dont have a gauge for this spell then create one
  #IF (%class(btn_affect_$affect) < 0) {
    #BUTTON btn_affect_$affect %concat(%replace(%proper($affect), "_", " "), " (@affects.", $affect, ")") {} {} {} {@affects.$affect} {} {} {Size} {144} {15} {} {1} {1} {} {} {Gauge|Lime|red|1350|100} {-19} {Bar_Affects} {Explore|Inset} {} {} {3}
  } { // If we have a gauge and its off, toggle it on
    #IF (!%trigger(btn_affect_$affect)) {#T+ btn_affect_$affect}
  }
}
// Loop through affects to remove expired spells buttons
#LOOPDB (@affects) {
  //If its not in the newAffects turn the gauge off
  #IF (!%iskey($newAffects, %key)) {
    #T- btn_affect_%key
  }
}
//Update affects list
#VAR affects $newAffects {_nodef} {Char_Data}
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