Announcement: Be excellent to each other.


Caravel Forum : DROD RPG Boards : RPG Feature Requests : Accessing a variable through another variable (Problem solved. Nevermind this thread.)
New Topic New Poll Post Reply
Poster Message
12th Archivist
Level: Smitemaster
Avatar
Rank Points: 789
Registered: 12-07-2008
IP: Logged
icon Accessing a variable through another variable (0)  
My problem is that I want to be able to access a variable, say "swordA", using _Sword to make the player start holding a custom sword without the use of the "Equipment" command. This can already be done if swordA is a value such 20000. Example:
Set var swordA = 20000
Set var _Sword = swordA
This will set the player's sword to whatever character who has an ID of 20000. However, this code will not work if swordA is a reference to another variable with a value. Example:
Set var swordA = 20000
Set var swordB = "$swordA$" (Using "Assign text")
Set var _Sword = swordB

This code does not work. One reason might be because the game is assigning _Sword to literally $swordB$ instead of the value referenced by swordB.

Long story short, it would be highly useful if the game could do that. In the case that _Sword is set to swordB and swordB references swordA when swordA does not contain an integer, _Sword would be set to "0" to prevent bad things from happening. (This is probably the current functionality that is preventing me from doing what I want to do, but I just wanted to mention it.)

If anyone knows a workaround, though, please share it.

____________________________
It was going well until it exploded.
~Scott Manley

Check out the DROD Wikia project here!

[Last edited by 12th Archivist at 01-24-2011 05:48 AM]
01-24-2011 at 04:07 AM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
TFMurphy
Level: Smitemaster
Rank Points: 3118
Registered: 06-11-2007
IP: Logged
icon Re: Accessing a variable through another variable (+8)  
Here's your problem.
12th Archivist wrote:
Set var swordA = 20000
Set var _Sword = swordA
After the first line, you have the following:
swordA = 20000

After the second, you have:
swordA = 20000
_Sword = 20000

So far, so good.

But when you do:
12th Archivist wrote:
Set var swordA = 20000
Set var swordB = "$swordA$" (Using "Assign text")
Set var _Sword = swordB
You get this after the first line:
swordA = 20000

...and this after the second line:
swordA = 20000
swordB = "20000"

...and this after the third line:
swordA = 20000
swordB = "20000"
_Sword = "20000" (illegal, so becomes 0)

First off, you can't set _Sword to a string of text. Secondly, you can't set swordB to a dynamically updating string: it turns "$swordA$" to "20000" the *moment* you set swordB to that. swordB no longer references swordA, because that reference was already dealt with.

If you want to change _Sword, then you can set it to a variable, and you can even have that variable set by referencing another variable, but you (1) can't set _Sword to text, and (2) should make sure you update the variables yourself. You can't change swordA and expect that some nested recursion will automatically update _Sword for you.

So what you could do is instead:
Set var swordA = 20000
Set var swordB = swordA
Set var _Sword = swordB

The above would set _Sword to 20000. But it doesn't mean that if you later change swordA that _Sword will automatically update: you can't do that (and honestly, that way lies trouble with recursion and nested problems). But since you'll usually be changing swordA manually, it isn't difficult to simply update _Sword yourself at the same time (especially if you have a Global Script that queries the variable and synchronises other variables with it every turn).
01-24-2011 at 04:40 AM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
12th Archivist
Level: Smitemaster
Avatar
Rank Points: 789
Registered: 12-07-2008
IP: Logged
icon Re: Accessing a variable through another variable (0)  
Thank you very much, TFMurphy. My script works now.

____________________________
It was going well until it exploded.
~Scott Manley

Check out the DROD Wikia project here!
01-24-2011 at 05:47 AM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
New Topic New Poll Post Reply
Caravel Forum : DROD RPG Boards : RPG Feature Requests : Accessing a variable through another variable (Problem solved. Nevermind this thread.)
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.