Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

Part 1: I think im okay with buttons locking even when overlapping partially, but i might be too lazy for writing the locking code to each button, so is there a way for everything to lock under the MacWindow without me doing it for each one individually?.. 

(And yes i want for the window to be able to move)

Part 2: Yeah, i don't remember if i knew about the targets thing in the zazz.wave, but if i did i would have a problem, 'cause i only have one note on each of b (b1, b2), so it didnt work on the first try... BUT i thought about just writing two times the same target in the list for each b's and it worked!

Part 3: So i want the script to start right when i click the name in the grid. Each name would change the number in the slider to certain thing. Then when i click the play button it would read the number in the slider and play the needed song!

* Sorry for taking a looong time to answer, I have school and everything like that in the back so i dont program often!

(+3)

Hi! Sorry for the delay, it's been a busy week. But I am so glad to see you back and working on your project!

This might be a little confusing but I'll do my best... we're going to change the MacWindow contraption a little bit. I'll explain the changes, and also just post a code block for the modified version afterwards in case that's more helpful to you.

There are two draggable canvases inside of the MacWindow contraption.
One is at the top and lets you move the window around the screen. The other is the one in the bottom corner that lets you  resize the window.

Inside of the scripts for both of these internal canvases they already have on release do event handlers that are doing something else. 

But since we'd also like them to do something when people "release" the contraption on the card (checking for buttons, then locking them) we can add a line saying "card.event.release" to both of the scripts:

on release pos do
field.locked:card.locked
card.event.release # This is the new line
end

This lets the release event from these canvases (when the window is moved or resized) also bubble up to the script for the MacWindow that you have on the card. And that lets us write another "on release do" event handler there, which does something specific to the card it's on.

Or, alternatively, here's the modified version in a codeblock:

%%WGT0{"w":[{"name":"macFieldWindow1","type":"contraption","size":[134,93],"pos":[193,184],"locked":1,"script":"on close do\n \nend\n\non resize do\n \nend\n\nbuttonset:button1,button2,button3\n\non release do\n each button in buttonset\n  button.locked:rect.overlaps[me button]\n end\nend","def":"macFieldWindow","widgets":{"close":{},"resize":{"pos":[113,4]},"title":{"size":[37,17],"pos":[48,1],"value":"Hello"},"drag_resize":{"pos":[118,77]},"field":{"size":[133,59],"locked":1,"value":{"text":["I am a draggable and resizeable window sporting a rich text field!\n","Try me!"],"font":["","menu"],"arg":["",""]}},"bar":{"size":[134,19]}}}],"d":{"macFieldWindow":{"name":"macFieldWindow","size":[59,71],"resizable":1,"margin":[22,34,33,33],"description":"a window frame in the style of MacOS 6, sporting a field as well as supporting dragging and resizing! The internal field is available  at x.field\nThis version has added an \"on release do\" event.","version":1,"script":"on get_title do title.text end\non set_title x do title.text:x end\non get_field do field end\non get_value do field.value end\non set_value x do field.value: x end\n\non view do\n field.locked:card.locked\n t:get_title[]\n if count t\n  title.font:\"menu\"\n  s:first title.font.textsize[t]\n  title.size:(s+10),title.size[1]\n  title.pos :(.5*card.size[0]-title.size[0]),title.pos[1]\n  title.show:\"solid\"\n else\n  title.show:\"none\"\n end\nend","template":"on close do\n \nend\n\non resize do\n \nend\n\non release do\n\nend","image":"%%IMG3ADsARwbAgHBILBqPyKSyCGo6n9CodEqtgobWrHYbxXK/YCnWeFWWl2Mz2dulBsLvZ/w6TRPp9TP6PW/O+UxsUH2DcIV+dUJ6ioRyi0t4Tn+PZ3mWX4STYoyBbo9qZIhrimKeYI2SiYB3qKJ7jJ6jra2RXLSznKygr5+6vmHAwILBxFbDxchdr8vMzADP0NHS09TV0rSDQtbb3NyNqEPd4uPPmbV+2uTq1n2akunr8dHuiO8B8vjl9Ydn+fh8psL5i8dEjp2BBFM5sodwHb1aAhuOe9gOnsRuf0Khu3dRHDaDHDt62xJRJLtmJkdqKZly2keGLau93BhTJkmLNaHN7JfzGsqe826GBApgJ8ueGQvSJKpvn9OjOSmCZNr0XMWhQJVuXEW16LmFUGvGAQeTqdSyRNspRJu10DecSNsowxp3ZbO7eI+U4ndp7cIsx0j97YtOLmDBogwTpmPuUza1i5zuLQi5sT2/Cj+O3Ysn06+v9TRLzix50piAxkan2vx3lerOqUHDtrpaMFnZpA2P1eg68x3coX9DVt17tWLOxgeTDfwttkHFyxFjBv719tZA0k1pd24sr3e8Rb+LRxME","attributes":{"name":["title","value"],"label":["Title","Text"],"type":["string","rich"]},"widgets":{"close":{"type":"button","size":[11,11],"pos":[9,4],"script":"on click do\n card.event[\"close\"]\nend","style":"invisible"},"resize":{"type":"button","size":[11,11],"pos":[38,4],"script":"on click do\n card.event[\"resize\"]\nend","style":"invisible"},"title":{"type":"field","size":[8,17],"pos":[-12,1],"locked":1,"font":"menu","show":"none","border":0,"style":"plain","align":"center"},"drag_resize":{"type":"canvas","size":[14,14],"pos":[43,55],"script":"on click pos do\n field.locked:1\nend\n\non drag pos do\n card.size:(me.offset-card.pos-16)|(title.size[0]+57),85\n view[]\n field.locked:1\nend\n\non release pos do\n card.event.release\n field.locked:card.locked\nend","show":"transparent","border":0,"draggable":1,"scale":1},"field":{"type":"field","size":[58,37],"pos":[0,18],"border":1,"scrollbar":1},"bar":{"type":"canvas","size":[59,19],"pos":[0,0],"script":"on click pos do\n field.locked:1\nend\n\non drag pos do\n card.pos:me.offset\nend\n\non release pos do\n field.locked:card.locked\n card.event.release\nend","show":"transparent","border":0,"draggable":1,"scale":1}}}}}

No more worrying about the contraption! Back to your cards, where we can modify the scripts inside each instance of the MacWindow in your project.

buttonset:button1,button2,button3

on release do
 each button in buttonset
  button.locked:rect.overlaps[me button]
 end
end

AND we need to do some important setup to define "rect.overlaps" and to customize "buttonset" for your project.

To get the rect module, we'll need to transfer it over from examples/draggable.deck. 

Decker > Resources... then select draggable.deck in the example folder and transfer "rect" to your current project.

To customize buttonset, you'll need to modify the list of the buttons that you want to lock/unlock when the MacWindow is over them. I just wrote a generic list while testing.

buttonset:button1,button2,button3

This can be in the MacWindow's widget script if there's only one mac window per card, or you can put it in the Card script if you have multiple MacWindows and they all need to lock/unlock the same set of buttons.

The reason why I'm defining the set of buttons this way instead of looking for every button on the card is because I figured that you might have some buttons that need to stay locked until something specific happens in the story... And if you do have special buttons like that, then you can put those specific button in a separate If statement.

on release do
 each button in buttonset
  button.locked:rect.overlaps[me button]
 end
 if somethinghappened.value
  specialbutton.locked:rect.overlaps[me specialbutton]
 end
end

Hopefully that will stop your story-related buttons from unlocking before they're supposed to.

I think you're all set on the zazz.wave stuff? So moving on to the music...

You might be able to skip the slider, but in either case, we're using grid.row to find the currently selected row.

If you want to move that value (the number of the selected row) over to a slider and use it from there, then you could do something like this inside the Grid's script:

on click row do
songslider.value:songgrid.row 
end

 And then inside the button you can do something like this if you're using the slider... (Remember that numbers start counting at 0!)

on click do
 if songslider.value=0
  play["firstsong"]
 elseif songslider.value=1
  play["secondsong"]
 end
end

Or if you'd like to skip the slider you can check the selected grid row from inside of your button like this:

on click do
 if songgrid.row=0
  play["firstsong"]
 elseif songgrid.row=1
  play["secondsong"]
 end
end

 Depending on the number of songs you're dealing with you may have a lot of elseif elseif elseif to add to your button script,  and if that's true then you might want to switch over to using a table instead at some point...  but if it's only a couple of them then this should be fine.

I'm also not sure what you're doing with your music, so I just put the generic play[] function there for now.

As always, change the names to the actual names of your widgets and songs and I'll try to be around to answer any more questions you may have!

(+1)
"if somethinghappened.value
specialbutton.locked:rect.overlaps[me specialbutton]
end
end"

Ok! everything are set up (with notes thing only)! But I dont understand how to make buttons unlock when the notes are overlapping them BUT are hidden since there is a button to hide and reveal notes....

I already tried different ways i couldve come up with like:

if me.show = "none"
 each button in buttonset
  button.locked:rect.overlaps[me button]0 (like i would done when unlocking a normal button to unlock it?)
 end

So i dont know...

Also a question... how would i make the window appear on each button in the same place with the same size and copying text from the previous one to everyone else on every card?.. I know it might be very hard but i have an idea to save its x and y on separate sliders and size on separate slider, and then the text saves to a special field. All of the sliders and fields for it would be on a separate card, from witch a window would take the information, but is there an easier way (if there is then please describe me only this one), if there isnt, please tell me how i can make and script the one i've come up with!

Thank you for all the hard work, I really appreciate it and will put you in the credits ofcourse, duuhh

(+1)

Alright, things are getting more complicated here but I think I have code snippets that answer most of your concerns. I may have missed something along the way. I'm really concerned I've missed something or not thought something through all the way on this one. Things are really getting more specific to the needs of your project and I can only write code for the things I know about it! I may have guessed wrong!

I'm going to switch to referring to the MacWindows as macFieldWindows now, since I think that's the version you're using (the resizable draggable one from the bazaar) and I'm going to be referring to them by the contraption name (def.name="macFieldWindow") in the scripts.

Also, it hadn't occurred to me when I was writing my last post that you could also "lock" plot buttons by hiding them (show: "none" is pretty much the same as locking a button to the player).

So, if you're hiding your plot buttons (show:"none") then buttonset could be a list of all buttons that lock/unlock  together. 

The "plot-related lock" would be their visibility, in that case.

But if you want your special plot buttons to be visible AND locked until they're ready then we'll still need to create a list of normal buttons that doesn't include the special one, and then do something special for the special button. 

It's just something that occurred to me while I was writing this up. Feel free to ignore it.

I'm going to try to do both things at once by automating the list of all buttons and also removing "specialbutton" from that list when we come back to the new "buttoncheck[]" function later in this post.

And just because it's useful to know, this kind of line:

button.locked:rect.overlaps[me button]

...is kind of like writing button.locked:0 or 1, except it gets the 0 or 1 from checking if those two things are overlapping. 

button.locked gets 0 if false and 1 if true.

Okay, hopefully I've got all my snippets in order for the real stuff! For macFieldWindow... We're going to make some new functions that will make them all match each other whenever there's a change, and we'll also need to make a tiny edit to the contraption again.

The edit to the contraption:

Open any macFieldWindow properties and then click [Prototype...] to go inside the contraption prototype area. Then use the menu [Prototype > Script] and put this line anywhere that's not inside of another script:

on get_animate do view end

This lets us send animate[]  to the mac windows to refresh their appearance. This avoids the widget visibly updating in front of your player when they move around your project after something about the mac windows has changed.

That's all we need to do here, so close the script viewer then use [Prototype > Close] to leave this area.

Making the macFieldWindows match:

These two new scripts should go in the Deck level script, because they need to be visible from everywhere.

This first one, "posupdate[]", makes a list of all the macFieldWindow contraptions and then makes them match the size and position of the specific widget that called the function (that's what it's referring to as "me" in the script). 

on posupdate do
 instances:raze each card in range deck.cards
  extract value where value..def.name="macFieldWindow" from card.widgets
 end
 (me drop instances)..pos:me.pos
 (me drop instances)..size:me.size
 instances..event.buttoncheck[]
 instances..animate[]
end

The second one, "noteupdate[]" lets you set the written section of the macFieldWindows to whatever you put inside the brackets.

on noteupdate x do
 instances:raze each card in range deck.cards
  extract value where value..def.name="macFieldWindow" from card.widgets
 end
 instances..value:x
 instances..animate[]
end

If it's just simple text you can write it as a string inside of quotes for short notes or if you want to prepare something longer with special formatting you can copy the contents of an existing field into them.

To use this in scripts anywhere in your project:

noteupdate["To Do: Investigate the Building"] # for short notes
noteupdate[anExistingField.value] # copies the contents of an existing field

That's all we need to do in the Deck Script, I think....

Changes to the script for the individual macFieldWindows:

on release do
 posupdate[]
end

on buttoncheck do
 buttonset:extract value where value..type="button" from card.widgets
 if me.show="none"
  buttonset..locked:0
 else
  each button in buttonset
   button.locked:overlaps[me button]
  end
 end
end

Now when a window is released (from moving or resizing) it will call the posupdate[] function (the thing we added up in the deck script) to make the others match. And that posupdate[] function we added also tells all the mac windows in your project to check if they're overlapping any buttons on their cards with their own personal buttoncheck[] functions.

The buttoncheck[] above is a generic one, which can be used on cards if you don't have any "specialbutton"s to worry about, and this is an example of a version of buttoncheck[] that does create an exception for a special button:

on buttoncheck do
 buttonset:extract value where value..type="button" from card.widgets
 if me.show="none"
  buttonset..locked:0
 else
  each button in buttonset
   button.locked:overlaps[me button]
  end
 end

 if somethinghappened.value & (me.show="none")
  specialbutton.locked:0
 elseif (somethinghappened.value=0)
  specialbutton.locked:1
 else
  specialbutton.locked:rect.overlaps[me specialbutton]
 end
end

This new version defines "buttonset" as all the things of type="button" on the card, like before, and then we check specialbutton again specifically.  This way you only need to write specific code for for the exceptions, and those exceptions can be different for each card's macFieldWindow.

The if statements after that look at different possible situations your specialbutton could be in:

  • If something happened and me(the macFieldWindow) is hidden, then the special button should be unlocked.
  • If something didn't happen then it should always be locked.
  • Else, if the above statements weren't true, then it'll check if the macFieldWindow is overlapping it and decide whether or not it should be locked based on that.

It's a little more complicated! But I hope you can follow along.

The last thing that I think you need right now, is how to tell the button that toggles your macFieldWindow's visibility that it should also cause a buttoncheck[] to happen.

And in a very simple case, for only the current card, it could look like this:

on click do
 macFieldWindow1.toggle["solid"]
 macFieldWindow1.event.buttoncheck[]
end

But maybe you want it to update the visibility of all the notes on all the cards?

I'm out of time for now, but feel free to let me know. Hopefully this is enough for you to work with for now! (And hopefully I wrote things correctly!)

For this last one I assumed the mac window had the default name when it's created: "macFieldWindow1", but if not then please change that to match your actual widget name. Anything that says "def.name="macFieldWindow" doesn't need to be changed. That kind of script is looking at the name of the prototype, not the individual widgets made from it.

And of course, specialbutton and somethinghappened are just placeholders for whatever you're really working on. :)

It's really lovely to see little glimpses of your project coming together from the questions you're asking.