26 posts
Posted 28 August 2014 - 04:47 AM
Hello CC Fans!
This simulator is about fish roaming around in the water.
This program is open sourced so you can do whatever you please with it as long as you give me some sort of credit.
Controls: press K to kill the fish (Alternative to using CTRL + T)press F to add life to the fish. (feeding it), press R to reset the positions & orientations of the fish
Press space to make the fish move (takes .5 of your fish's life) now automated, thanks to flaghacker and KingofGamesYami for help with that.
- Features:
- Startup Screen
- 3 fish (can be any color in the game with the exception of white and black)
- Seaweed Background
1 2 Ways to kill the fish (starvation, using the kill button or overfeeding)2 Controls now only one, as the fish now moves on its own.- 1 Health monitor
- Infinite food
- restart screen (uses latest version on pastebin)
Known Bugs:
- there are currently no known bugs
Pastebin:
http://pastebin.com/5x9Uu1pr OR:
pastebin get 5x9Uu1pr FishSimulator
Have a fun time with this! ;)/>
PS: I shortened the amount of lines from 629 to 461
Edited on 12 December 2014 - 01:24 AM
598 posts
Location
The United States
Posted 28 August 2014 - 01:29 PM
Pretty neat! I can't wait for more to be added to this :)/>
571 posts
Location
Some Fish Bowl in Ohio.
Posted 28 August 2014 - 07:26 PM
Do I make a cameo appearance?
26 posts
Posted 28 August 2014 - 10:25 PM
Pretty neat! I can't wait for more to be added to this :)/>
What should I add to this?
Edited on 28 August 2014 - 08:25 PM
598 posts
Location
The United States
Posted 28 August 2014 - 10:56 PM
Pretty neat! I can't wait for more to be added to this :)/>
What should I add to this?
Hm.. Well, now that I think about it, I can't think of any suggestions for this..
26 posts
Posted 28 August 2014 - 11:27 PM
Pretty neat! I can't wait for more to be added to this :)/>
What should I add to this?
Hm.. Well, now that I think about it, I can't think of any suggestions for this..
I could use help on making parallel work with this so you wouldnt need the space bar to update everything
;)/> when i tried the feeding wouldnt work
Edited on 28 August 2014 - 09:31 PM
656 posts
Posted 29 August 2014 - 10:47 AM
I could use help on making parallel work with this so you wouldnt need the space bar to update everything
;)/>/> when i tried the feeding wouldnt work
Pseudo code (I'm on mobile):
start timer
while true do
os.pullEvent
if timer
move
start new timer
if feed key
feed
end
end
No need to use the parallel API.
3057 posts
Location
United States of America
Posted 29 August 2014 - 01:27 PM
I could use help on making parallel work with this so you wouldnt need the space bar to update everything
;)/>/> when i tried the feeding wouldnt work
Pseudo code (I'm on mobile):
start timer
while true do
os.pullEvent
if timer
move
start new timer
if feed key
feed
end
end
No need to use the parallel API.
Let me clean up that code…
local id = os.startTimer()
while true do
local event = {os.pullEvent()}
if event[ 1 ] == "timer" and event[ 2 ] == id then
--#move
id = os.startTimer()
elseif event[ 1 ] == "key" and event[ 2 ] == "feed" then
--#feed
end
end
656 posts
Posted 29 August 2014 - 01:48 PM
Let me clean up that code…
local id = os.startTimer()
while true do
local event = {os.pullEvent()}
if event[ 1 ] == "timer" and event[ 2 ] == id then
--#move
id = os.startTimer()
elseif event[ 1 ] == "key" and event[ 2 ] == "feed" then
--#feed
end
end
Thanks, typing symbols is a pain on my phone. Scrolling even more…
26 posts
Posted 30 August 2014 - 12:58 AM
Let me clean up that code…
local id = os.startTimer()
while true do
local event = {os.pullEvent()}
if event[ 1 ] == "timer" and event[ 2 ] == id then
--#move
id = os.startTimer()
elseif event[ 1 ] == "key" and event[ 2 ] == "feed" then
--#feed
end
end
Thanks, typing symbols is a pain on my phone. Scrolling even more…
thanks guys! ill implement this in the program ASAP
26 posts
Posted 30 August 2014 - 01:17 AM
Let me clean up that code…
local id = os.startTimer()
while true do
local event = {os.pullEvent()}
if event[ 1 ] == "timer" and event[ 2 ] == id then
--#move
id = os.startTimer()
elseif event[ 1 ] == "key" and event[ 2 ] == "feed" then
--#feed
end
end
Thanks, typing symbols is a pain on my phone. Scrolling even more…
thanks guys! ill implement this in the program ASAP
Dang it! the feeding Still wont work…
--Variables
local fishX = 10
local fishY = 10
local fishHealth = 20
local space = 57
local feed = 33
local h = colors.green
local fishLook = true -- true means left false means right
--Functions
function fishFeed()
if key == feed then
term.setCursorPos(5,5)
term.setBackgroundColor(colors.lightBlue)
print("Feeding Your Fish!")
sleep(.50)
fishHealth = fishHealth+1
if fishY > 18 then
fishY = 2
elseif fishY < 2 then
fishY = 18
end
end
--Health ColorChangers
if fishHealth < 5 then
h = colors.red
elseif fishHealth < 10 then
h = colors.orange
elseif fishHealth > 15 then
h = colors.green
elseif fishHealth > 9 then
h = 1
elseif fishHealth < 5 then
h = colors.red
end
if fishHealth > 20 then
init()
term.setCursorPos(5,5)
term.setBackgroundColor(colors.lightBlue)
print("Your Fish Was Overfed!")
sleep(1)
term.setBackgroundColor(colors.black)
term.clear()
error()
end
if fishHealth < .5 then
init()
term.setCursorPos(5,5)
term.setBackgroundColor(colors.lightBlue)
print("Your Fish Starved To Death!")
sleep(1)
term.setBackgroundColor(colors.black)
term.clear()
error()
end
end
function fishMove()
term.setBackgroundColor(colors.lightBlue)
term.clear()
term.setCursorPos(1,1)
term.setTextColor(1)
term.write("Fish's Life: ")
term.setTextColor(h)
term.write(fishHealth)
term.setCursorPos(fishX,fishY)
term.setTextColor(colors.black)
term.setBackgroundColor(colors.orange)
if fishLook then
print("(O<")
else if fishLook == false then
print(">O)")
end
end
move = math.random(4)
fishHealth = fishHealth - .5
if move == 1 then
fishX = fishX-1
fishLook = true
elseif move == 2 then
fishX = fishX+1
fishLook = false
elseif move == 3 then
fishY = fishY-1
elseif move == 4 then
fishY = fishY+1
end
end
local id = os.startTimer(1)
while true do
local event = {os.pullEvent()}
if event[ 1 ] == "timer" and event[ 2 ] == id then
fishMove()
id = os.startTimer(1)
elseif event[ 1 ] == "key" and event[ 2 ] == feed then
end
end
3057 posts
Location
United States of America
Posted 30 August 2014 - 01:52 AM
while true do
local event = {os.pullEvent()}
if event[ 1 ] == "timer" and event[ 2 ] == id then
fishMove()
id = os.startTimer(1)
elseif event[ 1 ] == "key" and event[ 2 ] == feed then
--#nothing, absolutely nothing is shown happening here...
end
end
26 posts
Posted 30 August 2014 - 06:07 PM
while true do
local event = {os.pullEvent()}
if event[ 1 ] == "timer" and event[ 2 ] == id then
fishMove()
id = os.startTimer(1)
elseif event[ 1 ] == "key" and event[ 2 ] == feed then
--#nothing, absolutely nothing is shown happening here...
end
end
thanks for that… the program now automatically moves the fish without making it so you cant feed it. thanks guys!!!
26 posts
Posted 02 September 2014 - 03:26 AM
Ideas anyone? :P/>
EDIT: I have an idea in mind.
Edited on 02 September 2014 - 01:27 AM
513 posts
Location
Australia
Posted 05 September 2014 - 05:01 AM
You shouldn't be using sleep() when you're capturing os.timer events. If you feed your fish at the wrong time the sleep event captures and I think ignores the os.timer that fires, meaning the fish will be stationary and cannot be overfed.
I reckon you should add some more fish and maybe some seaweed. Feels a bit like a virtual aquarium which could be a nice thing to leave running on a monitor on a server for people to occasionally feed.
1852 posts
Location
Sweden
Posted 05 September 2014 - 03:22 PM
As nitro said, you shouldn't use sleep as it ignores timers.
That's because the sleep function is basically something like this
Spoiler
sleep = function( sRate )
local timer = os.startTimer( sRate )
repeat
local e = { os.pullEvent( "timer" ) }
until e[2] == timer
end
As you can see it uses the event system, and it only listens to a specific timer, this causes all other events and timers to be ignoredAnd I have a suggestion, since you posted a pastebin link you might as well remove the code in the post or put it in a spoiler.
Could you also post some screenshots? It would be nice to see how it looks without having to download it first.
26 posts
Posted 11 September 2014 - 05:04 AM
As nitro said, you shouldn't use sleep as it ignores timers.
That's because the sleep function is basically something like this
Spoiler
sleep = function( sRate )
local timer = os.startTimer( sRate )
repeat
local e = { os.pullEvent( "timer" ) }
until e[2] == timer
end
As you can see it uses the event system, and it only listens to a specific timer, this causes all other events and timers to be ignoredAnd I have a suggestion, since you posted a pastebin link you might as well remove the code in the post or put it in a spoiler.
Could you also post some screenshots? It would be nice to see how it looks without having to download it first.
good idea… but i dont really have a way to substitute sleep…
Edited on 11 September 2014 - 03:05 AM
513 posts
Location
Australia
Posted 11 September 2014 - 10:02 AM
I agree in your code it's quite hard- in future you should isolate drawing and updates in your program to make event handling like this easier.
This would be a very quick and dirty fix:
print("Feeding Your Fish!")
fishHealth = fishHealth+1.5
sleep(.50)
id = os.startTimer(1)
But I'd recommend isolating the draw and updates. That way you can fire separate timer events (wherever you would use a sleep call) and handle each one individually.
541 posts
Location
Melbourne, Australia
Posted 14 September 2014 - 10:46 AM
really awesome, however its a bit annoying when the fish swims over the life meter, after a minute of feeding and whatnot the fish and life meter completely froze.
26 posts
Posted 16 September 2014 - 05:35 AM
I agree in your code it's quite hard- in future you should isolate drawing and updates in your program to make event handling like this easier.
This would be a very quick and dirty fix:
print("Feeding Your Fish!")
fishHealth = fishHealth+1.5
sleep(.50)
id = os.startTimer(1)
But I'd recommend isolating the draw and updates. That way you can fire separate timer events (wherever you would use a sleep call) and handle each one individually.
How do you recommend i do that?
also i might make it so the food lasts longer and the food cap is doubled lol
Edited on 16 September 2014 - 03:35 AM
26 posts
Posted 24 September 2014 - 03:52 AM
Is anyone still here?
7508 posts
Location
Australia
Posted 24 September 2014 - 04:33 AM
try creating a thread in Ask a Pro to get help. You're more likely to get more visibility for your problem there.
26 posts
Posted 23 October 2014 - 02:49 AM
You shouldn't be using sleep() when you're capturing os.timer events. If you feed your fish at the wrong time the sleep event captures and I think ignores the os.timer that fires, meaning the fish will be stationary and cannot be overfed.
I reckon you should add some more fish and maybe some seaweed. Feels a bit like a virtual aquarium which could be a nice thing to leave running on a monitor on a server for people to occasionally feed.
I did just that B)/> also it works well with monitors now as you can fire the "monitor_click" event to feed now
try creating a thread in Ask a Pro to get help. You're more likely to get more visibility for your problem there.
Help?
7508 posts
Location
Australia
Posted 23 October 2014 - 03:15 AM
Help?
you were asking for help
26 posts
Posted 24 October 2014 - 09:07 PM
Help?
you were asking for help
Oh, sorry :(/>
26 posts
Posted 24 October 2014 - 09:20 PM
I am probably adding a red fish, and also maybe a lime fish
EDIT: the lime fish bugged out when I was testing it out so I didn't add one.
Edited on 24 October 2014 - 09:04 PM