dMZX Forums: String in string name? - dMZX Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

String in string name? Can it be done?

#1 User is offline   Spike 

  • I had nothing to do with it.
  • PipPipPip
  • Group: Members
  • Posts: 253
  • Joined: 24-October 00

Post icon  Posted 03 October 2006 - 08:19 PM

So I've got these strings:

set "$SpearSound" to "Stab.wav"
set "$SwordSound" to "Slash.wav"
set "$WhipSound" to "Snap.wav"


And I'm trying to reference them dynamically from another robot:

sam 250 "$&$Weapon&Sound"


Didn't work.
Any ideas? How would you guys do it?
0

#2 User is offline   Dr Lancer-X 

  • 電波、届いた?
  • Group: DigiStaff
  • Posts: 8,944
  • Joined: 20-March 02
  • Location:ur mom nmiaow

Posted 03 October 2006 - 08:22 PM

It takes some playing around to do it, and I can't quite recall at the moment. When I get to a computer that I can run MZX on it I'll try and find out again.

It _is_ doable, though. I've done it before several times.

EDIT: Actually, with what you're doing, there is no difficulty. Your command is just plain incorrect.

Essentially, what you're doing is this

sam 250 "$string"

Should be pretty clear why that won't work =p You need to interpolate it to a string, because the sam command is being fed the literal '$string' which is not what you want.
Posted Image
<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
0

#3 User is offline   Spectere 

  • Resident Spectere Fanboy
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 3,111
  • Joined: 18-June 04
  • Gender:Male
  • Location:Struthers, OH, USA

Posted 04 October 2006 - 12:41 AM

I'll take a peek through the docs...be right back...

Edit: Meh, couldn't really piece anything together that worked. It was easy getting "SwordSound" (and friends) but it doesn't seem to like evaluating that (unless I'm doing something wrong, with is likely).

This post has been edited by Spectere: 04 October 2006 - 01:00 AM

:)
0

#4 User is offline   Spike 

  • I had nothing to do with it.
  • PipPipPip
  • Group: Members
  • Posts: 253
  • Joined: 24-October 00

Posted 04 October 2006 - 12:55 AM

Sorry, typed it wrong, it was supposed to be &$&$Weapon&Sound&, which doesn't work.

Edit: I need it to read as "&$SpearSound&", as I've got some 20 different sounds I'll need to use, and I'd rather not have to have an If statement and a label for all of them.

This post has been edited by Spike: 04 October 2006 - 12:59 AM

0

#5 User is offline   Exophase 

  • Laughing on the inside.
  • Group: DigiStaff
  • Posts: 7,155
  • Joined: 23-October 00
  • Gender:Male
  • Location:Cleveland, OH

Posted 04 October 2006 - 01:48 AM

You've still got it wrong. You can't double interpolate strings because they only use &&. You have to do it in two steps.

set "$sound" "&$Weapon&Sound.sam"
sam 250 "&$sound&"

You could, of course, do things the old fashioned way and just use numbers to index them instead of strings.
~ ex0 has a kickass battle engine, without it you sux0rz! without it you sux0rz! ~

"The fact that I say I've one of the best, is called honesty." -Akwende
"Megazeux is not ment to be just ASCII, it is ANSI!" - T-bone6
"I hate it when you get all exo on me." - emalkay

Exophase can what Rubi-cant.
exoware is ware ur ware is exoware
ps. not loking 4 new membrs kthx
0

#6 User is offline   Spike 

  • I had nothing to do with it.
  • PipPipPip
  • Group: Members
  • Posts: 253
  • Joined: 24-October 00

Posted 04 October 2006 - 02:32 AM

Durr, I got it working a different way, just renamed my sound files and used
sam 250 "&$Weapon&.wav"

I feel really stupid now for not thinking of that earlier. Thanks for the help though!

This post has been edited by Spike: 04 October 2006 - 02:32 AM

0

#7 User is offline   Pyro1588 

  • wojtek
  • PipPip
  • Group: Members
  • Posts: 145
  • Joined: 20-October 02
  • Gender:Male
  • Location:Minnesota

Posted 04 October 2006 - 08:52 PM

what about this?
sam 250 "$('('Weapon')Sound').sam"

that's the easiest way to nest things...
but yeah, renaming them is the way to go.
edit: forgot the $.

This post has been edited by Pyro1588: 04 October 2006 - 08:53 PM

<Tox> bah. I may as well give in and shop australia. D:
<pyro1588> "welcome to australia, can i help you find what you're looking for?"
<Tox> pyro1588, I'm giving you the most reproachful of glares right now.
--------
Go show those nutty Koreans what us crazy Europeans are made of pirate.gif pirate.gif pirate.gif - Saike
<exophase> The old Commodore strategy of, "Go friggin' bankrupt!"
<wervyn> Go away! I'm writing the same engine I always do!
0

#8 User is offline   Dr Lancer-X 

  • 電波、届いた?
  • Group: DigiStaff
  • Posts: 8,944
  • Joined: 20-March 02
  • Location:ur mom nmiaow

Posted 04 October 2006 - 09:42 PM

Except &$Weapon&Sound is a string. You used an expression, AND you forgot two additional $ signs to designate the strings. The original problem was interpolating nested strings, so your solution doesn't work. Expressions work with numbers, not strings.

Please, people, test your code before posting it unless you are certain it will work. To be certain code will work, you need to actually look over it once before posting it.
Posted Image
<Malwyn> Yes, yes. Don't worry I'd rather masturbate with broken glass than ask you for help again. :(
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users