Author Topic: Scripting help (please?)  (Read 2446 times)

LeslieWooddavis

  • Newbie
  • *
  • Posts: 3
Scripting help (please?)
« on: July 11, 2010, 10:15:51 PM »
Tigabyte -

Since finding your program (by putting HyperCard into Google), I've decided I'd like to try and get back into designing games. I've started by re-making my old Clue game, originally written in HyperCard. (In case you are wondering, Mr. Body was killed by Miss Scarlett in the Library with the Wrench in this particular story. He broke her heart and their engagement, asking for the ring back - the cheap scoundrel.) Other scenarios will follow if I can figure out the scripting on this one.

Please bear with me.

1. I have a room (say the typical Hall in the Clue game). In the Hall there are several items. The Butler who answered the door, a wrench, a flower pot, a book, a door to another room. I would like to click on each of these items in the Hall then have the response described in field 1 ("Welcome to the Body Mansion, Mr. Detective." from the Butler). It would be easiest if I could put an invisible button on these items to put my message into field one (as I did in HyperCard) but apparently invisible buttons are not an option in HyperNext. Baring that impossibility, can I make a 'click area' (in this case the wrench) on the canvas of the Hall to put a statement into field 1? ("you have clicked on the wrench!" Or, "you've clicked on the flower pot!") Putting a visible button to do this deed on the canvas does work, but it's a bit risky. It often (but not always) disappears behind the canvas and can no longer be found.
On HyperCard (clicking an invisible or visible button on the canvas - assuming that button stayed on top - which it always did in HyperCard) the script would be:
OnMouseUp
Put "you have found the Wrench!" into Card field 1
End MouseUp

2. Next problem: Going to the card "Library" from the Hall. Easy enough with the goto option on the properties menu, but can I then put into field 1 (on the library card) the statement that I just arrived from the Hall? Evidently, anything after 'gotocard library' in the script is not accepted and gives me an error.
On HyperCard the script would be:
OnMouseUp
Goto card "Library"
Put "Hall" into card Field 1 -- in this instance 'Field 1' would be on the library card.
End MouseUp

3. Next uncertainty: Can I create a button to take me directly back to the hall? If I put in 'prior button' from your properties menu, it does not take me to the last card I was on (the Hall or some other previous room) but to the card immediately before the card I am now on (in this case into the Lounge where I do not want to go).
On HyperCard the script would be:
OnMouseUp
Go last card -- the last card being the Hall, not the Lounge
End MouseUp

4. Sound. I have asked this before, but I still haven't found a solution. I have a cat loitering in the hall. I would like to click on its button and have the cat purr (using the sound button on properties), but I would then like to have the sound of 'thunder' immediately following the cat's purr. Then, naturally, the cat utters a loud 'meow!' and runs away (ButtonSetView 5,0  with your scripting to get the cat to skitter away - I did figure that part out.) Silly for all this activity from the cat, of course, but it's part of the game. On your properties menu, only one sound can be added. I still haven't learned how to script a sound (SoundPlay (channel,filename) - the sound is purr.aiff - I have no idea what the channel would be, or exactly what you are asking for.
On HyperCard my script would be:
On OpenCard
show cd button "cat" -just in case the cat was missing when you got to the Hall
End OpenCard
On Mouseup -- clicking on the cat
Play "purr'
Play "Thunder"
Play "Meow!"
Hide me -- the cat disappears, which is why I would have to put "show button "cat" on OpenCard
End MouseUp

I realize that I am more or less asking you to recreate HyperCard, and I apologize for the comparison, but it was a programming language I understood and could write easily. Feel free to complain to your colleagues "this impossible woman is a real pain in the arse!" and tell me to go to the devil. I promise to completely understand and bother you no further.

Leslie
« Last Edit: January 01, 1970, 12:00:00 AM by Guest »

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 412
  • Here to help you
Re: Scripting help (please?)
« Reply #1 on: July 12, 2010, 08:54:42 AM »
Hi Leslie

Its great that your game was fully working in Hypercard so hopefully it should be just conversion to Hypernext with all the logic bugs already sorted out.

I should point out that although Hypercard and HyperNext are very similar there are many differences as Hypercard has a very powerful event driven engine whereas HyperNext's is much more limited. Also in Hypercard you can pass events up the hierarchy and choose which object will respond to them whereas in HyperNext its either the object clicked responds to them or else it doesn't and the event then vanishes. On the other hand HyperNext is much more "modern" with better graphics, colors and works on Macintosh and Windows.



Quote
1. I have a room (say the typical Hall in the Clue game). In the Hall there are several items. The Butler who answered the door, a wrench, a flower pot, a book, a door to another room. I would like to click on each of these items in the Hall then have the response described in field 1 ("Welcome to the Body Mansion, Mr. Detective." from the Butler). It would be easiest if I could put an invisible button on these items to put my message into field one (as I did in HyperCard) but apparently invisible buttons are not an option in HyperNext. Baring that impossibility, can I make a 'click area' (in this case the wrench) on the canvas of the Hall to put a statement into field 1? ("you have clicked on the wrench!" Or, "you've clicked on the flower pot!") Putting a visible button to do this deed on the canvas does work, but it's a bit risky. It often (but not always) disappears behind the canvas and can no longer be found.
On HyperCard (clicking an invisible or visible button on the canvas - assuming that button stayed on top - which it always did in HyperCard) the script would be:
OnMouseUp
Put "you have found the Wrench!" into Card field 1
End MouseUp

Yes, in HN its much easier to use a canvas, just use the canvas script and check for the mouse-click event, check where the mouse click occurred and then goto the relevant card etc.
There is a project on our website called "Solar System" - uses click on a picture of a planet and it takes them to another card loading the appropriate graphics.

Solar System project is in the bundle here - http://http://www.tigabyte.com/binaries/CreatorProjects.zip

Below is the script from the selection canvas. Note that it always goes to card 2 but you could easily make it go to a card dependent upon the room chosen.

Code: [Select]
Global objectID
Local evnum,mess

Put CanvasEventFN(1) into evnum

If evnum=1 Then
    Call FindObject
   If objectID>0 Then
       GotoCard 2
   EndIf
EndIf

and here is the global procedure "FindObject" that checks the mouse click x & y coords to determine which planet was selected. Its a bit messy as it is checking for relevant data but the coordinates bound matching should be clear.

Code: [Select]
Global objectAreas1,objectAreas2,objectCount
Global objectID

Local n,x,y,x1,y1,x2,y2,s1

Put 0 into objectID

Put CanvasMouseXFN into x
Put CanvasMouseYFN into y

For n=1 to objectCount
    Put line n of objectAreas1 into s1
    Put word 1 of s1 into x1
    Put word 2 of s1 into y1
    Put word 3 of s1 into x2
    Put word 4 of s1 into y2
    If (x>=x1) AND (x<=x2) Then
        If (y>=y1) AND (y<=y2) Then
            Put n into objectID
            GotoLabel 1
        EndIf
    EndIf
    Put line n of objectAreas2 into s1
    Put word 1 of s1 into x1
    Put word 2 of s1 into y1
    Put word 3 of s1 into x2
    Put word 4 of s1 into y2
    If (x>=x1) AND (x<=x2) Then
        If (y>=y1) AND (y<=y2) Then
            Put n into objectID
            GotoLabel 1
        EndIf
    EndIf
EndFor

Label 1



Quote
2. Next problem: Going to the card "Library" from the Hall. Easy enough with the goto option on the properties menu, but can I then put into field 1 (on the library card) the statement that I just arrived from the Hall? Evidently, anything after 'gotocard library' in the script is not accepted and gives me an error.
On HyperCard the script would be:
OnMouseUp
Goto card "Library"
Put "Hall" into card Field 1 -- in this instance 'Field 1' would be on the library card.
End MouseUp

Yes you can easily do this when the target card loads. The "Solar System" project uses this script to load the relevant planetary data picture etc. The planet is identified by the global variable objectID

Code: [Select]
Global objectID,objectNames,objectDescriptions
Global objectStats1,objectStats2,objectStats3,objectStats4
Global objectStats5,objectStats6,objectStats7,objectStats8
Global objectFileNames

Local s1
Put line objectID of objectNames into s1
TextSetValue(1,s1)

@ *** Load image into source canvas ***
Local fname
Put line objectID of objectFileNames into fname
LoadImage(1,fname,0)

@ Description
Put line objectID of objectDescription into field 1


@ ---- 8 lines of stats
Put '' into s1
Put line objectID of objectStats1 after s1
Put line objectID of objectStats2 after s1
Put line objectID of objectStats3 after s1
Put line objectID of objectStats4 after s1
Put line objectID of objectStats5 after s1
Put line objectID of objectStats6 after s1
Put line objectID of objectStats7 after s1
Put line objectID of objectStats8 after s1
Put s1 into field 2



Quote
3. Next uncertainty: Can I create a button to take me directly back to the hall? If I put in 'prior button' from your properties menu, it does not take me to the last card I was on (the Hall or some other previous room) but to the card immediately before the card I am now on (in this case into the Lounge where I do not want to go).
On HyperCard the script would be:
OnMouseUp
Go last card -- the last card being the Hall, not the Lounge
End MouseUp

It might be best to keep track of which card you are on using a global variable

Code: [Select]
Put CardIDFN into currentCard
HN has several Goto commands for going to previous card, next card but they refer to the absolute position of the card in the stack and not to which card was the last card visited. I'll add this function to the to-do list for the next release of HN.

By the way, there was a goto bug in the last release of HN v3.83 - to overcome it all cards targeted by a Goto should have something in their script because empty scripts did not initialize their Goto Handler.
http://[url=http://www.tigabyte.com/forums/viewtopic.php?f=22&t=50]http://www.tigabyte.com/forums/viewtopic.php?f=22&t=50[/url]



Quote
4. Sound. I have asked this before, but I still haven't found a solution. I have a cat loitering in the hall. I would like to click on its button and have the cat purr (using the sound button on properties), but I would then like to have the sound of 'thunder' immediately following the cat's purr. Then, naturally, the cat utters a loud 'meow!' and runs away (ButtonSetView 5,0 with your scripting to get the cat to skitter away - I did figure that part out.) Silly for all this activity from the cat, of course, but it's part of the game. On your properties menu, only one sound can be added. I still haven't learned how to script a sound (SoundPlay (channel,filename) - the sound is purr.aiff - I have no idea what the channel would be, or exactly what you are asking for.
On HyperCard my script would be:
On OpenCard
show cd button "cat" -just in case the cat was missing when you got to the Hall
End OpenCard
On Mouseup -- clicking on the cat
Play "purr'
Play "Thunder"
Play "Meow!"
Hide me -- the cat disappears, which is why I would have to put "show button "cat" on OpenCard
End MouseUp

Here is some ideas about playing sequences of sounds at Runtime

http://http://www.tigabyte.com/forums/viewtopic.php?f=22&t=59

I'll see about adding a new Sound command so that sounds are queued and not stopped when the new sound is called.


If I've missed answering some of your questions please just repost that part again.

I really hope you manage to get your games converted easily and don't hit some HN limitation requiring a lot of recoding.

Malcolm
« Last Edit: January 01, 1970, 12:00:00 AM by Guest »
I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.