Cycle through ALL hotspots - RESOLVED

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

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

Cycle through ALL hotspots - RESOLVED

Postby reneuend » Sun May 29, 2011 12:02 am

I believe the hotspot object is a collection under a collection of frame objects, which would mean I would need to cycle through all the frame objects and access the hotspots in each frame object.

frame(0)
- hotspot(0)
- hotspot(1)
frame(1)
- hotspot(0)
- hotspot(1)

Basically, what I need to do is cycle through all the hotspots in a game and check to see if it is enabled and what frame it came from.

When GM created the "Save Game" command, he had to save the state of the hotspots somehow. I need to do the same thing!

Any ideas?

I know a way around this, but it would make a little extra work for someone using the AMSaveLoadGame plugin and I really want to avoid it if possible.
Last edited by reneuend on Thu Jun 09, 2011 5:04 am, edited 1 time in total.
---


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

Postby GM-Support » Mon May 30, 2011 10:28 am

Hi reneuend,

to list all the hotspots that have been disabled (when using the "Hide and disable this hotspot (permanently)" option from the "Action" tab of the "Hotspot Properties"), you can use the following code:
Code: Select all
Sub ListDisabledHotspots
   Dim Output
   Output = "List of hotspots that are disabled:" + VbCrLf + VbCrLf
   For Each X In WindowObject.Disappear
          Output = Output + "- Hotspot #" + CStr(X.Value) + " from the frame named '" + X.Name + "'"
   Next
   MsgBox Output
End Sub


To reset that list (in order to enable all the hotspots that have been disabled), you can use the following code:
Code: Select all
Sub ResetDisabledHotspots
    For i = WindowObject.Disappear.Count To 1 Step -1
        WindowObject.Disappear.Remove i
    Next
End Sub


Best regards,
GM-Support
GM-Support
Forum Admin and Games Page admin
 
Posts: 2221
Joined: Thu Jun 05, 2003 7:52 pm

Postby reneuend » Mon May 30, 2011 1:48 pm

Thanks GM!

What I want to do is to save the hotspot state where they have been disabled. I should be able to do that with the first example by saving the framename and hotspot number.

With the disabled hotspots saved to a file, I can then use this to disable those same hotspots (reload a saved game) should they currently be enabled.

The only thing left is to loop through the saved list and disable the hotspots. Can you show me the code to do this?

'ListName is an array of the saved framenames
'ListHS is an array of saved hotspot numbers

'Will the following code work? I'm missing 1 line where I need to disable the hotspot. Can you show me how to disable a hotspot with the syntax you've shown me?

Code: Select all
For Each X In WindowObject
  For Y=1 to numListItems
         'find the matching framename and hs
         if X.Name = ListName(y) and cstr(X.Value) = ListHS(y) then 
                 'disable this hotspot! How?
         end if
    Next
Next
---


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

Postby GM-Support » Tue May 31, 2011 12:50 pm

Hi reneuend,

"WindowObject" represents the main window of the game (also called "Form" in Visual Basic 6). It is the highest-level object in the User Interface, and it contains all the other objects and controls of the game.

There is only one "WindowObject", and it is not an array, so I don't think it is useful to call "For Each X In WindowObject".

If you want to iterate through all the hotspots, you should use "For Each X In Hotspot" (because Hotspot is a an array), as shown in the examples section of the page http://adventuremaker.com/help/vbscript_objects.htm

The WindowObject contains a variable called "Disappear", which is actually a dictionary of "name-value" pairs (where "name" is the name of the frame and "value" is the number that identifies the hotspot in that frame) that is used to tell the Adventure Maker engine which hotspots whould be disabled (or "hidden").

Please be aware that you need to save both the frame name AND the hotspot number if you want to later be able to uniquely identify a hotspot (because two frames may contain the same hotspot number).

If what you are trying to achieve is a custom load/save feature, the only thing that you have to do is save the content of the "WindowObject.Disappear" dictionary to a file or to some other place, and then to load it back by overriding (replacing) the content of the "WindowObject.Disappear" dictionary (i.e. restore its previously saved values) : the Adventure Maker engine will automatically take care of enabling/disabling the hotspots when you modify the "WindowObject.Disappear" dictionary.

So, to sum up, here is what you can do:

1) Save the content of the "WindowObject.Disappear" dictionary by reading all the items that it contains (using the "ListDisabledHotspots" example that I posted).

2) Load the saved game by resetting the "WindowObject.Disappear" dictionary and populating it with the values from the saved game

3) Adventure Maker will automatically enable/disable the hotspots based on the content of the modified "WindowObject.Disappear" dictionary. If you want to force Adventure Maker to update immediately, you can call the "Action.UpdateHotspotsState" command, or reload the frame by calling "Action.GoToFrame(Action.GetCurrentFrameName)".

The difficult part is to save/load the information contained in the "WindowObject.Disappear" dictionary. The first code example shows how to list all the items contained in that dictionary. From that example you can deduce a way to save the information to a file or to another location.

For your information, here is the Visual Basic code of Adventure Maker that corresponds to the saving of that information (it will not work directly in VBScript, but it is just to give you the general idea):
Code: Select all
Dim temp
temp = WindowObject.Disappear.Count
Write #1, temp
For i = 1 To temp
    Write #1, Game.Disappear.Item(i).Name
    Write #1, Game.Disappear.Item(i).Value
Next

where "Write #1" is a VB6 command to write a new line into a file.

Then, to load it back, you will need to read the saved file and populate the "WindowObject.Disappear" dictionary accordingly. Here is the corresponding Visual Basic code of Adventure Maker (again, it will not work directly in VBScript, but it is just to give you the general idea):
Code: Select all
ResetDisabledHotspots
Dim temp_DisappearCount
Input #1, temp_DisappearCount
Dim temp_name
Dim temp_value
For i = 1 To temp_DisappearCount
    Input #1, temp_name
    Input #1, temp_value
    WindowObject.Disappear.Add temp_name, temp_value
Next

where "Input #1" is a VB6 command to read a line from a file.

Best regards,
GM-Support
GM-Support
Forum Admin and Games Page admin
 
Posts: 2221
Joined: Thu Jun 05, 2003 7:52 pm

Postby reneuend » Tue May 31, 2011 2:02 pm

(SOLVED! I just replaced Game with WindowObject.)

Hi GM,

There is an error in the following code. The object Game is not defined apparently:

Code: Select all
    Write #1, Game.Disappear.Item(i).Name
    Write #1, Game.Disappear.Item(i).Value


The error message reads:

Error in Component_ObjectEvent. Object required: 'Game'

If I get past this, I think I'm done. Can you assist please?

Thanks very much for your very useful explanation and help!
---


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

Postby reneuend » Wed Jun 08, 2011 7:01 pm

I'm getting a mismatch error on the following line. The variables I'm using are strings. :(

I also tested it with string constants and still got a mismatch error.

Code: Select all
WindowObject.Disappear.Add temp_name, temp_value


Example of the values I'm passing in:
temp_name = "plane crash"
temp_value = "21"

Code: Select all
WindowObject.Disappear.Add "test1", "test2"

Using string constants also caused a mismatch error


:?: Any ideas why I'm getting a mismatch error on this? :?
---


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

Postby Lyberodoggy » Wed Jun 08, 2011 10:43 pm

I consider it possible that the value variable is an integer and not a string, therefore giving a mismatch

EDIT: I tested the method with the second argument being an integer and it worked for me
User avatar
Lyberodoggy
Administrator
 
Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby reneuend » Wed Jun 08, 2011 11:06 pm

Well....you're right...kinda...if I hardcode the values it works, but when I use cInt or cLng to cast the second value, it's not working! :(

(update)
I checked the variables using VarType(). The second value is returning a 2. This means its of type dbInteger. So, why doesn't it work? I'm so confused. :?

I tested each parameter separately by using the other parameter as a constant.

test #1: "Plane Crash", nValue

test #2: sName, 21

both of these tests threw the mismatch error. But if I use constants in both:
test #3: "Plane Crash", 21
then it works.

any suggestions? I can't use hard-coded values.

:shock:
---


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

Postby Lyberodoggy » Thu Jun 09, 2011 12:12 am

Try using the Execute command:

Code: Select all
Execute "WindowObject.Disappear.Add """+temp_name+"""," +cstr(temp_value)
User avatar
Lyberodoggy
Administrator
 
Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby reneuend » Thu Jun 09, 2011 12:25 am

OK. That got it to stop erring out. I've never used the Execute command! Thanks!

Now, here is the issue. I thought this command was to disable those hotspots. Does it mean I need to do more to hide this hotspots too?
---


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

Postby Lyberodoggy » Thu Jun 09, 2011 12:57 am

The execute command is pretty useful when working with functions that need constant values but the programmer needs the values to be variable. It actually executes the given string during runtime, therefore replacing the attempts we 've done in the past in various scripts like plugins, to simulate this effect with CreateTimedEvent with a small time interval

As for the hotspots: if they didn't hide then you probably have inserted the wrong values. When I tried it the hotspots i added to the list were disabled and disappeared from the screen.
You could also try UpdateHotspotStatus (i think that's the one) or RefreshWindow, in case the frame hasn't been redrawn for the changes to take effect
User avatar
Lyberodoggy
Administrator
 
Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby reneuend » Thu Jun 09, 2011 1:20 am

Maybe you can see something. Everything works except that the hotspots are not going away.

hotspotstate25.ini:
plane crash,21
plane crash,22
plane crash,27
plane crash,28


Here is my subroutine:

Code: Select all
sub AM_LoadHotspotState(gamecnt)

ResetDisabledHotspots

Dim temp_DisappearCount
Dim data
Dim aHotspots
Dim sFile
Dim sName
Dim nValue

sFile = "hotspotstate" & gamecnt & ".ini"
data = AM_GetAllFileContents(sFile)
aHotspots = split(data,vbcrlf)  'each array element contains a pair: <frame>,<hotspot>
lNumItems = ubound(aHotspots) - 1

For i = 0 To lNumItems

  sName = CStr(trim(AM_GetWord(1,aHotspots(i),",")))
  nValue = CInt(trim(AM_GetWord(2,aHotspots(i),",")))

MsgBox "set WindowObject disappear dictionary: " & sName & " / " & nValue

  If not sName = "" Then
      Execute "WindowObject.Disappear.Add """+sValue+"""," +CStr(nValue)
      'Action.UpdateHotspotsState
      Action.RefreshWindow
  Else
    MsgBox "Name is empty: " & sName & " / " & nValue
  End If

Next

End Sub
---


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

Postby Lyberodoggy » Thu Jun 09, 2011 1:58 am

Well I have located a possible mistake, if I am right this line:
Code: Select all
Execute "WindowObject.Disappear.Add """+sValue+"""," +CStr(nValue)

should have been
Code: Select all
Execute "WindowObject.Disappear.Add """+sName+"""," +CStr(nValue)
User avatar
Lyberodoggy
Administrator
 
Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby reneuend » Thu Jun 09, 2011 2:11 am

GASP!!! :shock:

I'm sooooo glad you are around Lyberodoggy! As busy as you have been, I was wondering when you'd be around again!

Thanks!

(update) It works now...Very much appreciated!!
---


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

Postby Lyberodoggy » Thu Jun 09, 2011 2:43 am

Well, you are welcome :)
User avatar
Lyberodoggy
Administrator
 
Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens


Return to Adventure Maker Technical Support and Bug Reports

Who is online

Users browsing this forum: No registered users and 2 guests