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


Joined: 15 Jul 2019
Posts: 9

PostPosted: Thu Jun 09, 2022 4:57 pm   

Creating a fictional alien language
 
Afternoon friends!

I was recently asked for help creating a special language in-game that only one character could speak. I had thought it would be a simple task of simply substituting some letters out for others, but I am running into a problem: I can only get cmud to substitute one character out of a string, whether I use the #sub, %subregex, #oninput, or %replace commands. I've been trying to nest them somehow but to no avail. Any thoughts?
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4662
Location: Pensacola, FL, USA

PostPosted: Thu Jun 09, 2022 7:30 pm   
 
I would probably loop through each character of the string and use a #SWITCH, just to ensure you don't end up swapping one char into another char that will get swapped out later.

Code:
#LOCAL $translation
$decode=@message
#WHILE ($decode) {
  $char=%left($decode, 1)
  $decode=%leftback($decode, 1)
  #LOCAL $newchar
  #SWITCH ($char)
    ("a") {$newchar=x}
    ("b") {$newchar=j}
    ("c") {$newchar=w}
    ("d") {etcetera}
    {$newchar=$char}
  $translation=%concat($translation, $newchar)
  }
#PRINT {Translation: $translation}
_________________
Discord: Shalimarwildcat
Reply with quote
AzahDSL
Newbie


Joined: 15 Jul 2019
Posts: 9

PostPosted: Fri Jun 10, 2022 7:30 am   
 
Thanks for the quick response!

Unfortunately, I'm having some difficulty running it. I tossed it into a command input trigger to automate it and format it for my mud (Dark and Shattered Lands), but it seems to latch onto the first character of the message and spits out that character for the number of characters in the message.

Code:
alien %1


Code:
#va message %1
#LOCAL $translation
$decode=@message
#WHILE ($decode) {
  $char=%left($decode, 1)
  $decode=%leftback($decode, 1)
  #LOCAL $newchar
  #SWITCH ($char)
    ("a") {$newchar=z}
    ("b") {$newchar=y}
    ("c") {$newchar=x}
    ("d") {$newchar=w}
    ("e") {$newchar=v}
    ("f") {$newchar=u}
    ("g") {$newchar=t}
    ("h") {$newchar=s}
    ("i") {$newchar=r}
    ("j") {$newchar=q}
    ("k") {$newchar=p}
    ("l") {$newchar=o}
    ("m") {$newchar=n}
    ("n") {$newchar=m}
    ("o") {$newchar=l}
    ("p") {$newchar=k}
    ("q") {$newchar=j}
    ("r") {$newchar=i}
    ("s") {$newchar=h}
    ("t") {$newchar=g}
    ("u") {$newchar=f}
    ("v") {$newchar=e}
    ("w") {$newchar=d}
    ("x") {$newchar=c}
    ("y") {$newchar=b}
    ("z") {$newchar=a}
    {$newchar=$char}
  $translation=%concat($translation, $newchar)
  }
#PRINT {Translation: $translation}
say $translation


This is what happens:

Code:
alien hello world

Translation: ssssssssssss
say ssssssssssss
You say 'ssssssssssss'
Reply with quote
AzahDSL
Newbie


Joined: 15 Jul 2019
Posts: 9

PostPosted: Fri Jun 10, 2022 2:47 pm   
 
I'm a dummy! I think I got it figured it out. It really is the %subchar command, I was just using it wrong.

Code:
#oninput {alien %1} {whisper %subchar(%1, abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ, xkeazlvudvi'sicevirvcplzvaXKEAZLVUDVI'SICEVIRVCPLZVA)}


I suppose my final question would be... is there any way to sub one character for two using the %subchar command? Quotes, commas, brackets, and parentheses seem to have no effect, it just substitutes one character for another 1:1 from the first list to the second.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4662
Location: Pensacola, FL, USA

PostPosted: Fri Jun 10, 2022 4:16 pm   
 
Ahhh i see the issue, instead of %leftback use %right.
You could edit my loop to check on two characters at a time, but you would have to ensure it makes a match before redefining what is left to $decode.
It should also be able to handle changing punctuation and spacing.
_________________
Discord: Shalimarwildcat
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4662
Location: Pensacola, FL, USA

PostPosted: Fri Jun 10, 2022 4:55 pm   
 
Make yourself a list of the 2 char combinations you wanna check for.

Code:
#LOCAL $translation
$decode=%params
#WHILE ($decode) {
  #LOCAL $newchar
 
  //Checking two characters at a time
  $doubles=ch|sh|ll|etc
  $char=%left( $decode, 2)
  #IF (%ismember( $char, $doubles)) {
    $decode=%right( $decode, 2)
    #SWITCH ($char)
      ("ch") {$newchar=zj}
      ("sh") {$newchar=gf}
      {$newchar=$char}
    $translation=%concat( $translation, $newchar)
    #CONTINUE
    }
 
  //Checking one character at a time
  $char=%left( $decode, 1)
  $decode=%right( $decode, 1)
  #SWITCH ($char)
    ("a") {$newchar=z}
    ("b") {$newchar=y}
    ("c") {$newchar=x}
    ("d") {$newchar=w}
    ("e") {$newchar=v}
    ("f") {$newchar=u}
    ("g") {$newchar=t}
    ("h") {$newchar=s}
    ("i") {$newchar=r}
    ("j") {$newchar=q}
    ("k") {$newchar=p}
    ("l") {$newchar=o}
    ("m") {$newchar=n}
    ("n") {$newchar=m}
    ("o") {$newchar=l}
    ("p") {$newchar=k}
    ("q") {$newchar=j}
    ("r") {$newchar=i}
    ("s") {$newchar=h}
    ("t") {$newchar=g}
    ("u") {$newchar=f}
    ("v") {$newchar=e}
    ("w") {$newchar=d}
    ("x") {$newchar=c}
    ("y") {$newchar=b}
    ("z") {$newchar=a}
    {$newchar=$char}
  $translation=%concat( $translation, $newchar)
  }
#PRINT {Translation: $translation}
_________________
Discord: Shalimarwildcat
Reply with quote
AzahDSL
Newbie


Joined: 15 Jul 2019
Posts: 9

PostPosted: Fri Jun 10, 2022 5:04 pm   
 
Oohhh... that does work, and it substitutes one character for multiple! I'll fool around with this for a bit longer. Thank you!
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4662
Location: Pensacola, FL, USA

PostPosted: Sat Jun 11, 2022 4:03 am   
 
Could make it a lot less ugly by using using a dbVar instead of a switch as well.

#IF (%ismember($char, %dbkeys(@dbVar))) {$newchar=%db(@dbVar, $char)} {$newchar=$char}

But that requires the translation variable... would allow the same code to work more readily with several different languages though.
_________________
Discord: Shalimarwildcat
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4662
Location: Pensacola, FL, USA

PostPosted: Sat Jun 11, 2022 4:54 am   
 
Code:
#FUNCTION translate($lang, $message, $debug) {
  $key=%db(@tongues, $lang)
  #IF ($key=%null) {
    #PRINT Error: $lang is an unknown language!
    #EXIT
    }

  #LOCAL $translation
  $decode=$message
  #WHILE ($decode) {
    #LOCAL $newchar

    $char=%left($decode, 2)
    #IF (%ismember($char, %dbkeys($key))) {
      $newchar=%db($key, $char)
      $decode=%right( $decode, 2)
      $translation=%concat( $translation, $newchar)
      #CONTINUE
      }

    $char=%left($decode, 1)
    $decode=%right($decode, 1)
    #IF (%ismember($char, %dbkeys($key))) {$newchar=%db($key, $char)} {$newchar=$char}
    $translation=%concat( $translation, $newchar)
    }

  #IF ($debug) {
    #PRINT Original Message: $message
    #PRINT Translation $lang: $translation
    }
  #RETURN $translation
  }


With this you could then do something like:

#PRINT @translate(toElven, "How are you doing today?")
or
#FORALL %dbkeys(@tongues) {#CALL @translate(%i, @gibberish, 1)}
_________________
Discord: Shalimarwildcat
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