Make a variable variable?

This forum is meant for posting anything related to Adventure Maker that doesn't fit in the other forums.Please post technical questions in the Technical Support Forum!

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

Make a variable variable?

Postby juhuwoorps » Sat Feb 20, 2010 3:56 am

I'm sitting here and smash my head on the desk!
I want to handle this:

click a hotspot and start a sub
in the sub i want to change a variable.but i want to use the sub for differents HS

so my thinking was this:

calling the sub with

mysub(get_hotspot_number)


this is my sub:
sub mysub(GHN)

newvar+cstr(GHN)="new assets"
end sub


my problem is that newvar dont work

I want it like this:

if the HS who is clicked has the number 5 I want to change the variable called newvar5

hope its a bit understandable.
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Postby Mystery » Sat Feb 20, 2010 4:38 am

To be honest I'm not quite understanding what you are trying to do. As far as I understand newvar1-5 are variant variables? And all of them can get "new asset" assigned? Or not?

Anyhow just as an idea (and maybe it's not at all what you want):

hsnum is an integer variable.
newvar1, newvar2 etc. are variant variables.

VBS Procedures:

Code: Select all
Sub get_hotspot_number
hsnum=Action.GetHotspotNumber

Select Case (hsnum)
  case "1":
    newvar1="new assets"
Case "2":
    newvar2="new assets"
Case "3":
    newvar3="new assets"
End Select
End Sub


In the Hotspot Properties:
Code: Select all
get_hotspot_number


Please post if I'm completely off track with my idea from what you intend to do.
User avatar
Mystery
Forum Admin and Games Page admin
 
Posts: 2990
Joined: Sat Feb 04, 2006 8:12 am
Location: Switzerland

Re: Make a variable variable?

Postby Lyberodoggy » Sat Feb 20, 2010 8:00 am

juhuwoorps wrote:so my thinking was this:

calling the sub with

mysub(get_hotspot_number)


The procedure should be called with the command
Code: Select all
mysub Action.GetHotspotNumber
User avatar
Lyberodoggy
Administrator
 
Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby juhuwoorps » Sat Feb 20, 2010 11:22 am

My problem is not calling the sub, the problem is that the variable isn't built correct.

Code: Select all
newvar+cstr(GHN)="new assets"


if i try this I get an error message
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Postby Lyberodoggy » Sat Feb 20, 2010 2:49 pm

yeah, that's not possible in any programming language. in the left of the = operator you can have one variable, not a sum.

What you need is this code:

Code: Select all
Set Ref=GetVariableReferenceFromName("newvar"+cstr(GHN))
   Ref.value="new assets"
User avatar
Lyberodoggy
Administrator
 
Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens


Return to Adventure Maker General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron