Posting the Value of a Variant Variable on the Screen

This forum is meant for requesting technical support or reporting bugs.

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

Posting the Value of a Variant Variable on the Screen

Postby Sedani Studio » Wed Mar 11, 2015 2:10 am

Hello all:

I am working on a little math puzzle, and wanted to get your advice. Please see the attached picture. The idea right now is this: The player will click on a number from each column to set the value for three different numbers. I am using 3 variant variables (column1, column2 and column3) to establish the value of the three numbers by the square the player clicks on. For example, if the player clicks on the 2 in the first column, the first column value = 2. On each of the hotspots, I have coded in the ADVANCED tab of the hotspot properties (this is the code from the second hotspot on the leftmost column):

column1 = 1


I also have established a variant variable (prod) to calculate the product of the three numbers selected. If the three numbers selected are 2, 2 and 1, the product is 2x2x1 = 4. As stated, this is housed in another variant variable. When I coded it, it reads:

prod = column1*column2*column3

Is there a way to have the program display the product on the screen? In the picture, I'm trying to have it end up in the brown box. If the product (prod) is 8, I want it to update automatically and show that number in the brown box. I've looked through the VBS references on the site, and can't figure out a way to do this.

In debugging, the column1, column2 and column3 variables seem to be working, but not the prod variable. I'm not sure if this is related to my concern, but thought it was relevant to mention.

Thank you!
Attachments
Capture.JPG
Capture.JPG (39.71 KiB) Viewed 1456 times
User avatar
Sedani Studio
Member
 
Posts: 35
Joined: Tue Aug 12, 2008 4:26 pm
Location: Colorado, USA

Re: Posting the Value of a Variant Variable on the Screen

Postby Sedani Studio » Wed Mar 11, 2015 2:32 am

Aaahh.. I did find a way to get this to work by having the frame link to itself. The problem was that the "prod" value was initialized on a previous frame, but doesn't show unless the frame reloads. It's not super elegant, but works. However, I'm sure you all have better ways of doing this! Please send those suggestions!
User avatar
Sedani Studio
Member
 
Posts: 35
Joined: Tue Aug 12, 2008 4:26 pm
Location: Colorado, USA

Re: Posting the Value of a Variant Variable on the Screen

Postby reneuend » Wed Mar 11, 2015 5:27 am

Hello Sedani!

First, I would set these as integer variables, but if it works, then we'll ignore that.

Here is how I would set the Result value:

1. Right-click on the screen and create a Text object.
2. Enter anything you want. It won't matter because when the frame loads, we will update it. But be sure to enter something so we can see it after you finish creating it.
This should be Textbox(1). You can check by hovering over the text. Now, left-click and drag the textbox to the Result area.
3. From this Frame's properties - Advanced Tab - Procedures:

Code: Select all
Sub SetResult()
  prod= column1*column2*column3
  text(1).caption = cstr(prod)
End Sub


4. From the Frame's properties - Advanced Tab:
(Call the new procedure)
Code: Select all
  SetResult   


5. From each hotspot with the numbers that the player can change, update the result after updating the Hotspot value
(Call the new procedure)
Code: Select all
  SetResult   



by the way, prod in my case doesn't have to be defined in the Variables section because it is only used locally in the sub. So, I could have called it anything I wanted.

That should do it!
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2686
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Re: Posting the Value of a Variant Variable on the Screen

Postby Sedani Studio » Wed Mar 11, 2015 6:07 am

Thank you! Your advice mirrors what I ended up doing right after I posted the question and that "duh" moment hit me. I hadn't thought of creating the subroutine like you did, however, and that was very helpful. Although my workaround is working, it's all about elegant solutions for me, so I'm going to try yours out.

That's the second time you've helped, Reneuend. Thank you!
User avatar
Sedani Studio
Member
 
Posts: 35
Joined: Tue Aug 12, 2008 4:26 pm
Location: Colorado, USA

Re: Posting the Value of a Variant Variable on the Screen

Postby Sedani Studio » Fri Mar 13, 2015 5:54 am

Just tried it - it worked great! Much more efficient than my solution!

One thing - is there a way to have it do a short transition before updating the number like an alphablend? That was one advantage to reloading the frame, and I was wondering if it would work with calling the subroutine. I'll check the VBS pages to see if there is a language reference there.

Thank you again - I appreciate the insights I gained. As I said, the elegant solutions are the ones I prefer, so thank you again Reneuend!
User avatar
Sedani Studio
Member
 
Posts: 35
Joined: Tue Aug 12, 2008 4:26 pm
Location: Colorado, USA

Re: Posting the Value of a Variant Variable on the Screen

Postby reneuend » Fri Mar 13, 2015 12:19 pm

Glad I could help! :mrgreen:
on the hotspot advanced tabs, add a line at the end to recall this same frame with alphablending.

SetResult
Action Goto Frame ...



To make it cleaner, move the text().caption line from SetResult () to the last line in frames advanced tab, so we are only calling it once per calculation change.
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2686
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA


Return to Adventure Maker Technical Support and Bug Reports

Who is online

Users browsing this forum: Bing [Bot] and 3 guests

cron