Slice Menu Example

Upload your games here. Download other people's games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Slice Menu Example

Post by Bob the Hamster »

A little tutorial script showing how to make a simple menu using a slice collection



Scripts are included in the zip file, but here they are again

Code: Select all


define constant(18, second)
global variable(1, my choice)


plotscript, my event with a choice, begin
  my choice := choose a thing
  show text box(1)
  wait for text box
end


plotscript, choose a thing, begin
  variable(col)
  col := setup choose a thing
  
  variable(holder, cursor)
  holder := lookup slice(sli:choice holder, col)
  cursor := lookup slice(sli:cursor, col)
  
  variable(sl, need update)
  sl := first child(holder)
  
  variable(result)
  result := -1
  need update := true
  while(true) do(
    # Input
    if(keypress(cancel key)) then(
      result := -1
      break
    )
    if(keypress(use key)) then(
      result := slice child index(sl)
      break
    )
    if(keypress(right key)) then(
      sl := next sibling(sl)
      if(sl == none) then(sl := first child(holder))
      need update := true
    )elseif(keypress(left key)) then(
      sl := previous sibling(sl)
      if(sl == none) then(sl := last child(holder))
      need update := true
    )
    
    # Update
    if(need update) then(
      set slice width(cursor, slice width(sl))
      set slice height(cursor, slice height(sl))
      move slice to screen pos(cursor, slice screen x(sl), slice screen y(sl), second / 3)
      play sound(sfx:select8bit)
      need update := false
    )
    
    wait(1)
  )

  cleanup choose a thing(col)
  exit(result)
end

script, setup choose a thing, begin
  suspend player
  exit(load slice collection(0))
end

script, cleanup choose a thing, col, begin
  free slice(col)
  wait(second / 4)
  resume player
end

slice_menu_example0000.png
slice_menu_example0000.png (4.17 KiB) Viewed 2395 times
Attachments
slice_menu_example.zip
(1.92 MiB) Downloaded 160 times
Post Reply