Else Heart.Break()

Else Heart.Break()

dunbaratu 8. okt. 2015 kl. 18.01
My Slurpie Program
I have finally finished my Slurpie program, a tool I made to help me manage an inventory of all the computers in my slurp list. The tool is designed to be carried with me on a floppy, and interfaces with a computer back at home base that acts as the server for the database holding the names of all the known machines I've used the floppy on in the past, and the shorthand nickname aliases I've given them. It then gives me the option to open a text menu where I can browse the list with up/down arrows to pick a machine, and slurp.

If you have no idea what I'm talking about, then never mind. It would be a spoiler to explain those terms.

What I'm wondering is, how much of a spoiler is it to reveal the programs themselves? Is that considered bad form to show them here in the forum?
< >
Viser 19 av 9 kommentarer
Apo Wulf 8. okt. 2015 kl. 20.42 
I would always encourage them myself. Just note in the Title that it is a Program. We should have a Program/Example code Sub-Forum. I should post my Relational Database
Sist redigert av Apo Wulf; 8. okt. 2015 kl. 20.44
Ointment 8. okt. 2015 kl. 22.58 
In general, this game needs more, not less, discussion. Mark that your post is programming spoilers, and then share that ♥♥♥♥! Sounds awesome!
dunbaratu 8. okt. 2015 kl. 23.54 
Okay here it is, but warning, this is a big spoiler if you haven't gotten very far in the game and haven't learned much of the programming yet.

If you don't know how these ideas work, then don't read this yet until you've done all of them:

connecting, slurping, memories, floppy usage

Okay you have been warned.

-------- Everything below this line should be considered a Spoiler ----
---- I didn't use spoiler tags because they interfere with your ---
---- ability to cut and paste from the text in the spoiler section ---

------------------------------------------------------------------------------------------------------


Introducing Slurpie DB:
The system to manage your own slurpable computer alias list:

This is composed of two parts: a server computer and a floppy you keep with you and walk around with. There are two different programs, one for the server, and one to keep on the floppy.

Part 1: The server side.
=================

1.1 Choose a server computer that fits the following criteria:
----------------------------------------

1.1.1 - It must be somewhere you can easily access its console on a regular basis.
1.1.2 - It must be some computer no other Person uses (don't use a desk machine).
1.1.3 - It must be able to Connect()
1.1.4 - It must be able to use Memories (SaveMemory(), LoadMemory())
1.1.5 - It must have a console (no headless computers).

Choosing one of the extraneous humidity reporting computers as a server fits these criteria. I'm using the humidity computer at the foot of the stairs in the Lodge_underwater room in my game.

1.2 Install the following program on it to act as the server functionalitry:

######## Slurpie DB, the server-side program ############# ####### AssertFunc() # Ensure needed function is there or bomb out: void AssertFunc( string fName ) if HasFunction(fName) #good else string msg = "Error: This computer can't" msg += " do the "+fName+"() function." msg += " Run it on one that can." Say(msg) Quit() end end AssertFunc("GetMemories") AssertFunc("LoadMemory") AssertFunc("SaveMemory") AssertFunc("Connect") AssertFunc("Input") ClearText() Print(Name()) var keys = GetMemories() loop Print("") Print("Slurpie DB.") Print("") Print("Currently knows " + (Count(keys)) + " hosts.") Print("") if Count(keys) > 0 var max = Count(keys) max = max - 1 # why can't I do Count(keys)-1? number i = Input("host [0.."+max+"] : ") if i < 0 or i >= Count(keys) Print("out of range") else Print(keys[]) Print(" With Nickname " + LoadMemory(keys[])) string c = Input("(S)lurp, (D)elete, or (N)either? ") if c == "s" or c == "S" Connect(keys[]) Slurp() else if c == "d" or c == "D" string yn = Input("Confirm? (y/n) ") if yn == "y" or yn == "Y" EraseMemory( keys[] ) keys = GetMemories() #list is smaller now end end end else break # don't keep looping the message if input is # being skipped. end end
This program will let you manage the list, and delete things from it, when at the server console, as well as slurp from the server console to any machine in the list.

Part 2: The floppy program you carry with you
--------------------------------------------

2.1 Copy this floppy program (see below) onto a trash floppy you'll carry around with you at all times:

2.2 (Edit the line that says string slurpieDB = ...... to make it match the name
of whichever computer you installed the server onto in Part 1 above.(

2.3 To use it: Walk up to a computer you want to add to the slurp DB, or one that is already in the slurp DB, and replace its program with BootFromFloppy(), and use your floppy on it.

It will ask for a nickname for the machine. Type something short that will print nicely on a menu, so it won't have to use the super long name. Then it will ask you if you want to
slurp now. If you say no, then there's nothing else to do - you added the machine to the list, but that's it. You can revert the computer's program back to the original and be on your way. On the other hand if you want to slurp now, you will get a menu showing you all the other machines you've added to the list (there needs to be at least 2 machines on the list for this to work). You can pick the one you want with the arrows and hit space. It will get the real machine name, connect to it, and slurp you.


########### Slurpie DB, the client-side floppy ############# ######## ######## ######## EDIT THIS SETTING: ######## ######## # Change to the name of the computer where you # installed the Slurpie DB server program: string slurpieDB = "Lodge_Underwater_MediumSewerComputer_MediumSewerComputer_1" # Note: the following aren't used but I left them in for # use in the future if Height() and Width() ever get fixed. # # Maybe edit these some times? I think everything # uses the same universal font but I'm not sure: number fontHeight = 10 number fontWidth = 8 # There should be no edits required past this line # ----------------------------------------------------- ####### AssertFunc() # Ensure needed function is there or bomb out: void AssertFunc( string fName ) if HasFunction( fName ) #good else string msg = "Error: This computer can't" msg += " do the "+fName+"() function." msg += " Run it on one that can." Say( msg ) Quit() end end AssertFunc( "Name" ) AssertFunc( "Connect" ) AssertFunc( "Slurp" ) AssertFunc( "HasFloppy" ) AssertFunc( "Input" ) AssertFunc( "GetUser" ) AssertFunc( "Height" ) AssertFunc( "Width" ) ########## GetNumDisplayRows # A workaround to get the screen height in rows # from the user looking at the screen, since # Height() appears to be hardcoded to 256 regardless # of screen size in version 1.0.6 of Heart.Break(), # and there's no way to calculate it: number GetNumDisplayRows() ClearText() loop i from 35 to 4 Print(i) end Print("3 Screen height query:") Print("2 What is the biggest") PrintS("1 number you see?") number n = Input(" ") ClearText() return n end ########## PickMenu() # # This function is more complex than I wanted, and I # should probably break it up into smaller functions # at some point now that I got it working. # # Returns a number for how far into # the PickMenu the choice was. Returns # -1 if the user quits. # number PickMenu( string title, var picks ) # These aren't actually usable at the moment, # because Width() and Height() just return the same # thing all the time, so these values aren't being # used yet: number textHeight = Int(Height() / fontHeight) number textWidth = Int(Width() / fontWidth) number pick = -1 number topIndex = 0 number max = Count(picks) max -= 1 # needs to be an extra step because Count() does # not like being used in an expression in Sprak. number topDisplayRow = 1 number numDisplayRows = GetNumDisplayRows() - 1 if numDisplayRows < 1 numDisplayRows = 1 end number pickDisplayRow = 1 + Int(numDisplayRows / 2) # Ensure keypress is released from whatever prev # thing was happening. to avoid "bounceback" loop if IsKeyPressed("space") #continue else break end end ClearText() bool picked = false loop # ----- Redraw display, only if pick is # ----- outside currently showing choices: # ----- (causes new screenful when arrowing # ----- past the ends of the shown sublist.) if pick < topIndex or pick >= topIndex + numDisplayRows if pick < topIndex topIndex = (pick - numDisplayRows) + 1 if topIndex < -1 topIndex = -1 pick = -1 end end if pick >= topIndex + numDisplayRows topIndex = pick end ClearText() Print(" ") # forces all graphic primitives erased Text(0,0,title+": ") PrintMenuSubset( slurpie, pick, picks, topIndex, topDisplayRow, numDisplayRows) end # ---- Draw where the pick is now: Text(0,topDisplayRow + (pick - topIndex), "->") number oldPick = pick DisplayGraphics() # ---- Move the pick on arrows, or accept current bool keyPressed = false loop if IsKeyPressed("up") pick -= 1 if pick < -1 pick = -1 end keyPressed = true end if IsKeyPressed("down") pick += 1 if pick > max pick = max end keyPressed = true end if IsKeyPressed("space") picked = true keyPressed = true end Sleep(0.1) # just to prevent busy loop if keyPressed break end end if picked break else # pick has moved, so erase where it was before Text(0,topDisplayRow + (oldPick - topIndex), " ") end end return pick end ####### PrintMenuSubset void PrintMenuSubset( var slurpie, number pick, var picks, number topIndex, number topDisplayRow, number numDisplayRows) number nMinusOne = numDisplayRows - 1 #workaround Sprak bug loop row from 0 to nMinusOne number i = row + topIndex number screenRow = topDisplayRow + row if HasIndex(picks,i) string str = "["+i+"] " + picks[] Text(2, screenRow, str) else if i == -1 Text(2, screenRow, "<<quit>>") end end end ######## BuildNicks var BuildNicks( var slurpie, var hosts ) var nicks = [] loop key in hosts Append( nicks, slurpie.LoadMemory(key) ) end return nicks end ############# ### MAIN ### ############# ClearText() DisplayGraphics() DisplayGraphics() Print( "My Name is..." ) Print( " " + Name() ) Print( "Connecting to slurpieDB..." ) var slurpie = Connect( slurpieDB ) var hosts = slurpie.GetMemories() bool exists = slurpie.HasMemory(Name()) string oldNick = "" if exists oldNick = slurpie.LoadMemory(Name()) Print( "Already in DB as: " ) Print( " " + oldNick ) end Print( "New nickname for this Machine..." ) if exists Print( "Or hit return to keep nickname." ) end string nick = "" loop nick = Input( ">" ) if nick == "" and exists == false # nothing - repeat loop else break end end if nick == "" #nothing - can't find the 'not' operator. grr. else Print( "Adding my name to slurpieDB..." ) slurpie.SaveMemory( Name(), nick ) # Re-obtain hosts because the list has just changed: hosts = slurpie.GetMemories() end var hostCount = Count( hosts ) Print( "slurpieDB now has " + hostCount + " hosts." ) # Ensure flushed input: loop if IsKeyPressed("space") # loop until this is false else break end end string yes_no = Input( "Do you wish to Slurp Now (y/n)? " ) var nicks = BuildNicks( slurpie, hosts ) DisconnectAll() # ensure only dest will be connected if yes_no == "y" or yes_no == "Y" number pick = PickMenu( "Choose destination:", nicks ) if pick >= 0 Print( "Connecting to:" ) Print( " " + hosts[] ) var dest = Connect( hosts[] ) Slurp() end end Print( "Program done." )

If you want to manually hack a non-console or non-floppy machine to add
it to the list without using the floppy:

# To add this console-less computer to the slurpie DB under a nickname: # string slurpieDB = "whatever machine name you used for the server above" var c = Connect(slurpieDB) c.SaveMemory(Name(), "some nickname here") # now it's in the slurpie DB
Sist redigert av dunbaratu; 9. okt. 2015 kl. 0.11
Quillbolt_h 23. mars 2016 kl. 10.00 
No, not really. If you put them in spoilers, then it should be fine.
thepurplesensation 2. feb. 2017 kl. 6.44 
Really cool work, using it right now, thanks for this.
BUBBL3 3. feb. 2017 kl. 1.41 
Thanks for posting your code, I tried to use it but i cant boot stuff from a floppy, am I doing something wrong? i went to a computer(floppy data reader) and replaced the code with BootFromFloppy() and then it starts smoking if I try to boot it. any ideas?
cybersol 4. feb. 2017 kl. 11.42 
Take the floppy with the code out of your bag and hold it in your hand before using the computer you have modified to boot the floppy.
dunbaratu 5. feb. 2017 kl. 8.04 
It smokes because it encountered an error. In this case the error was that you told it to BootFromFloppy when there wasn't a floppy present for it to boot from.

To make it know which floppy to boot from, you have to have the floppy in your hand when you activate the computer's BootFromFloppy() program.
Billibus Maximus 2. jan. 2018 kl. 16.09 
Awesome work! I'm going to incorporate some of these ideas into my playing.
< >
Viser 19 av 9 kommentarer
Per side: 1530 50