This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Tjakka5's profile picture

RPG GAME! [V 1.0] [MASSIVE UPDATE!] [BETA]

Started by Tjakka5, 04 April 2013 - 10:16 PM
Tjakka5 #1
Posted 05 April 2013 - 12:16 AM
And we're in Beta guys :D/>

V 1.0.1 –Some bugfixes and such.
http://pastebin.com/mV94veBL

V 1.0
http://pastebin.com/bVh3Mepq

Done:

Movement
Able to click thingies.
UI
Multiple worlds
Different kinds of swords with description.
Different kinds of armor with description.
Leveling up system.

Planned:

Menu
Mobs
Magix :)/>
Bosses
Proper worlds
More armor/swords
Storyline maybe?
Save and load the game
More?


Older versions.
SpoilerAlpha:
Spoilerv.07
http://pastebin.com/QX119XgL

v.04
http://pastebin.com/XGqEjKD3/

v.03
http://pastebin.com/hRvepdnV/

v.01
http://pastebin.com/yUiCXFmV
theoriginalbit #2
Posted 05 April 2013 - 12:30 AM
Its good to see another game on the forums. Can't wait to see it finished.

You may benefit from using this function


local function centerWrite(msg, y, yOffset)
  local sw, sh = term.getSize()
  local yPos = y or sh/2 + (yOffset or 0) -- if y is not provided make it the middle of the screen, the yOffest variable is to move the text around the center, so if -1 is provided it will be 1 line above the center of the screen, if 2 is provided it will be 2 below the center
  local xPos = sw/2 - #msg/2 + (#msg % 2 == 0 and 1 or 0) -- find the start position of the text, if the text is an even size shift the position by +1 so that is still looks as though it is in the center
  term.setCursorPos(xPos, yPos)
  write(msg)
end

You can then just do this

centerWrite("P R E S S   A N Y   K E Y") -- this will be printed in the middle
centerWrite("T O   C O N T I N U E", nil, 1) -- this will be printed 1 line below the center
-- your code to wait for key press
centerWrite("R P G   G A M E", nil, -4) -- this will be printed 4 lines above the center

-- another example
centerWrite("S O M E  S E T  T E X T", 4) -- this will be printed at line 4
centerWrite("S O M E  S E T  T E X T", 4, 1) -- this will still be printed at line 4, offset is ignored when you provide a y position
Edited on 04 April 2013 - 10:31 PM
Tjakka5 #3
Posted 05 April 2013 - 01:25 AM
-snip

Thank you sir, I, however do not think about using this function, as I do not yet fully understand it.
I also do not need it for no, but if I find that I will need it later, I will definatly use it.


Next plan BTW is to make it Auto Update, as I am working on this on various places.
LuaEclipser #4
Posted 05 April 2013 - 11:40 AM
if you don't understand print Center, then you probably should work on that before you make an updater. (unless you are better with PHP) im not stopping you though. learn from your mistakes. right?
mikey53591 #5
Posted 05 April 2013 - 03:38 PM
Hey there! I've actually wanted to do the same type of project myself, but with the raw Lua Language and i've been doing my fair share of research to get started.

First off, I'd recommend learning tables and how to use them.
They're super useful.

Second, as a demonstration of using a table to make it easier to index and recall data, I'll change this:

local playerName = "Steve"
local xpGained = 0
local xpLevel = 0
local inventory = {"nil", "nil", "nil", "nil", "nil"}
local weapon = "nil"
local health = 20
local hunger = 20
local armor = 0
local damage = 1,5

To this:

player={
name="Steve"
xpLevel = 0
inventory={
  [1]=nil,
  [2]=nil,
  [3]=nil,
  [4]=nil,
  [5]=nil
},
weapon={
  damage={
   min_dam=1,
   max_dam=5
  }
},
armor={
  protection=0
},
}

With this, you'll be able to recall any information very easily whenever you need it, as well as set the data to a new value when an event happens, such as getting more XP, a new weapon, etc.
oeed #6
Posted 05 April 2013 - 03:42 PM
Hey there! I've actually wanted to do the same type of project myself, but with the raw Lua Language and i've been doing my fair share of research to get started.

First off, I'd recommend learning tables and how to use them.
They're super useful.

Second, as a demonstration of using a table to make it easier to index and recall data, I'll change this:

local playerName = "Steve"
local xpGained = 0
local xpLevel = 0
local inventory = {"nil", "nil", "nil", "nil", "nil"}
local weapon = "nil"
local health = 20
local hunger = 20
local armor = 0
local damage = 1,5

To this:

player={
name="Steve"
xpLevel = 0
inventory={
  [1]=nil,
  [2]=nil,
  [3]=nil,
  [4]=nil,
  [5]=nil
},
weapon={
  damage={
   min_dam=1,
   max_dam=5
  }
},
armor={
  protection=0
},
}

With this, you'll be able to recall any information very easily whenever you need it, as well as set the data to a new value when an event happens, such as getting more XP, a new weapon, etc.

Yea, going object oriented is a very good way to go in general. Especially with an RPG.
theoriginalbit #7
Posted 05 April 2013 - 05:27 PM
Yea, going object oriented is a very good way to go in general. Especially with an RPG.
And or game engine. It allows multiple instances of game objects without having to do some serious coding and duplication to do so.
Tjakka5 #8
Posted 05 April 2013 - 09:01 PM
-snip

With this, you'll be able to recall any information very easily whenever you need it, as well as set the data to a new value when an event happens, such as getting more XP, a new weapon, etc.

I was actually planning to make that a table right now!
I dont know why I though of that when I made those variables… It would have been much smarter, 'cause I can store it in files pretty easialy then!

BTW: I think I have though of a nice layout, which I hope will be made pretty soon!
TheOddByte #9
Posted 07 April 2013 - 01:15 AM
Its good to see another game on the forums. Can't wait to see it finished.

You may benefit from using this function


local function centerWrite(msg, y, yOffset)
  local sw, sh = term.getSize()
  local yPos = y or sh/2 + (yOffset or 0) -- if y is not provided make it the middle of the screen, the yOffest variable is to move the text around the center, so if -1 is provided it will be 1 line above the center of the screen, if 2 is provided it will be 2 below the center
  local xPos = sw/2 - #msg/2 + (#msg % 2 == 0 and 1 or 0) -- find the start position of the text, if the text is an even size shift the position by +1 so that is still looks as though it is in the center
  term.setCursorPos(xPos, yPos)
  write(msg)
end

You can then just do this

centerWrite("P R E S S   A N Y   K E Y") -- this will be printed in the middle
centerWrite("T O   C O N T I N U E", nil, 1) -- this will be printed 1 line below the center
-- your code to wait for key press
centerWrite("R P G   G A M E", nil, -4) -- this will be printed 4 lines above the center

-- another example
centerWrite("S O M E  S E T  T E X T", 4) -- this will be printed at line 4
centerWrite("S O M E  S E T  T E X T", 4, 1) -- this will still be printed at line 4, offset is ignored when you provide a y position

I always use this, And I think it would be simpler for him..


w,h = term.getSize() --Gets the size of the monitor/terminal

function centerPrint(y,text)
   term.setCursorPos(w/2 - #text/2, y) --Sets the cursor position to the middle
	  write(text) --Writes the text
  end

centerPrint(h/2,"This is some centered text!")
theoriginalbit #10
Posted 07 April 2013 - 06:19 AM
I always use this, And I think it would be simpler for him..
The only main difference between yours and mine is this bit

(#msg % 2 == 0 and 1 or 0)

Which just insures that it always LOOKS like it is in the centre of the screen. Even length strings require that offset of 1 to look good.
Tjakka5 #11
Posted 08 April 2013 - 08:38 AM
Okay, I wasnt working on it this weekend, but I just added the centerprint function, and I have to admit…

Its pretty awesum.
theoriginalbit #12
Posted 08 April 2013 - 08:39 AM
Okay, I wasnt working on it this weekend, but I just added the centerprint function, and I have to admit…

Its pretty awesum.
Told you :P/> it does make it very easy.
Tjakka5 #13
Posted 08 April 2013 - 11:06 PM
So… Yesterday evening.. damn…


I was like "Lets just add this function, and then go to sleep"
It became "Ya know, I feel like programming, lets just get this map going. […] Okay, thats good, but I realy need to sleep now… But I would realy like to see the player run around… […] …But then I need this function… […] Oh, and this needs to be added too… […] Hm, why wont this work and- WAIT, IS IT THIS LATE?!"

So now I'm tired and there will hopefully be a new version out this evening, which has:

-First testing map done…
-Map properties.
-Key clicking options.
-Tick is done.
-And the basics for the player to run around…

Also, what is the best way to 'store' a map, this is how I'm doing it now:

-- testMap1
-- ''[]'' is a block, ''  '' is air.
local testMap1x1 = {"[]", ''[]'', ''  '', ''  '', ''[]''}
local testMap1x2 = {''  '', ''  '', ''  '', ''[]'', ''[]''}

local testMap1x1Props = {''solid'', ''solid'', ''air'', ''air'', ''solid''}
local testMap1x2Props = {"air'', ''air'', ''air'', ''solid'', ''solid''}

And how I load it for now…


-- Load testMap1
for i = 1, 5 do
  term.write("" ..testMap1x1[i]
end
print("")
for i = 1, 5 do
  term.write("" ..testMap1x2[i]
end

I have a better Idea for storing the properties, and loading it, but how do I save it better?
Tjakka5 #14
Posted 10 April 2013 - 01:28 AM
Woopsy, something went wrong, now there a bugs, and some things arent implemented…

Expect a v 0.4 soon, maybe tonight, but dont expect to much.
Jian #15
Posted 10 April 2013 - 08:41 AM
Also, what is the best way to 'store' a map, this is how I'm doing it now:

-- testMap1
-- ''[]'' is a block, ''  '' is air.
local testMap1x1 = {"[]", ''[]'', ''  '', ''  '', ''[]''}
local testMap1x2 = {''  '', ''  '', ''  '', ''[]'', ''[]''}

local testMap1x1Props = {''solid'', ''solid'', ''air'', ''air'', ''solid''}
local testMap1x2Props = {"air'', ''air'', ''air'', ''solid'', ''solid''}

I would recommend changing the setup you have here. Instead of having two separate tables for the map with one map defined inside of it, have a table with possible items across all maps and then a table to represent them on a map.

So basically right now you have 2 possibilities.. a box which is solid or air…

you could display those like this


mapProps = {
	box = { render = "[]" , solid = true } ,
	air = { render = " " , solid = false } ,
}

which allows you to do more things, like color for example..


mapProps = {
	"box" = { render = "[]" , solid = true , bgColor = colors.brown , fgColor = colors.orange } ,
	"air" = { render = " " , solid = false , bgColor = colors.lightBlue  } ,
}

You should also consolidate the maps into one table. You can use the labels as your xPos and then the labels inside of that as your yPos..


testMap1 = {
[1] = { "box" , "box" , "air" , "air" , "box" } ,
[2] = { "air" , "air" , "air" , "box" , "box" }
}


If you can make it a single character instead of "air" or "box" , it would be really easy to make maps with a few strings in a table. Sort of how paint and the .nfp format works.
Not sure if any of this is actually useful but I hope I helped steer you in the right direction.
Tjakka5 #16
Posted 11 April 2013 - 07:29 AM
^ I was planning on doing that, but wasnt sure how to do that, so thanks for that.

Also, since I didnt have time yet, I will now update the program! Expect it withing 20 minutes!

EDIT: Incase I'm not able to upload it now, here is V 0.3 (Sloppy and dumb, but it has progress): pastebin.com/hRvepdnV
Tjakka5 #17
Posted 11 April 2013 - 07:57 AM
Yay! v.04 is out!
Sadly, there is a game breaking bug, and I dont have time to fix it right now, so if anyone could figure it out for me, cake will be given!

v.04:

http://pastebin.com/XGqEjKD3/
Tjakka5 #18
Posted 12 April 2013 - 04:28 AM
HumpedieBUMPdum.

Okay, I can't figure out why it ain't working D:
I need help! Posting this in 'Ask a Pro' now!
dmitchell94 #19
Posted 15 April 2013 - 07:14 PM
love to see some screenshots
Tjakka5 #20
Posted 15 April 2013 - 10:50 PM
love to see some screenshots

I'll try to make v 0.5 and upload it together with some screenshots.
Tjakka5 #21
Posted 22 April 2013 - 04:40 AM
Dawah?
New version after 11 days?!

Yep, movement is in, a proper testmap, ETC.

pastebin.com/QX119XgL
Tjakka5 #22
Posted 22 April 2013 - 04:41 AM
EDIT: Woopsy something went wrong there, ignore this post.
Tjakka5 #23
Posted 22 April 2013 - 11:19 PM
No feedback anymore?
Come on guys, i've been working on this a lot…
RiokuTheSlayer #24
Posted 24 April 2013 - 12:34 PM
Awesome! Nice to know someone takes weeks just to get movements done. :P/>
Tjakka5 #25
Posted 03 May 2013 - 02:01 PM
Awesome! Nice to know someone takes weeks just to get movements done. :P/>

Oh well, it's working anyways.

Also, massive update coming soon!
MASSIVE!!!
TeaPartyIdiot #26
Posted 05 May 2013 - 03:06 PM
Its good to see another game on the forums. Can't wait to see it finished.

You may benefit from using this function


local function centerWrite(msg, y, yOffset)
  local sw, sh = term.getSize()
  local yPos = y or sh/2 + (yOffset or 0) -- if y is not provided make it the middle of the screen, the yOffest variable is to move the text around the center, so if -1 is provided it will be 1 line above the center of the screen, if 2 is provided it will be 2 below the center
  local xPos = sw/2 - #msg/2 + (#msg % 2 == 0 and 1 or 0) -- find the start position of the text, if the text is an even size shift the position by +1 so that is still looks as though it is in the center
  term.setCursorPos(xPos, yPos)
  write(msg)
end

You can then just do this

centerWrite("P R E S S   A N Y   K E Y") -- this will be printed in the middle
centerWrite("T O   C O N T I N U E", nil, 1) -- this will be printed 1 line below the center
-- your code to wait for key press
centerWrite("R P G   G A M E", nil, -4) -- this will be printed 4 lines above the center

-- another example
centerWrite("S O M E  S E T  T E X T", 4) -- this will be printed at line 4
centerWrite("S O M E  S E T  T E X T", 4, 1) -- this will still be printed at line 4, offset is ignored when you provide a y position

Great code idea! I might use it soon!
Tjakka5 #27
Posted 06 May 2013 - 10:44 AM
And we're in version 1.0 guys!
I have been working on this version a lot, and I hope you guys will like it!
TorakTu #28
Posted 06 May 2013 - 04:38 PM
It was working until I got into the lower room.. then I got JAVA out of bound ( array ) errors.. Yea.. JAVA.. hmmmm… I was playing this in CCDesk 6.2

My guess is your constantly running a loop counter and it ran as high as it could go.

As simple as it was, it was still cool to walk around.

Keep up the good work. :D/>
nutcase84 #29
Posted 06 May 2013 - 04:42 PM
Screenies would be nice.
Tjakka5 #30
Posted 07 May 2013 - 05:36 AM
It was working until I got into the lower room.. then I got JAVA out of bound ( array ) errors.. Yea.. JAVA.. hmmmm… I was playing this in CCDesk 6.2

My guess is your constantly running a loop counter and it ran as high as it could go.

As simple as it was, it was still cool to walk around.

Keep up the good work. :D/>

Yes, thats still something I'm working on to fix…
Basically, it's constantly checking if the player is on X spot on X map every 0.X seconds…
How would I fix this?
TorakTu #31
Posted 07 May 2013 - 07:42 AM
It was working until I got into the lower room.. then I got JAVA out of bound ( array ) errors.. Yea.. JAVA.. hmmmm… I was playing this in CCDesk 6.2

My guess is your constantly running a loop counter and it ran as high as it could go.

As simple as it was, it was still cool to walk around.

Keep up the good work. :D/>

Yes, thats still something I'm working on to fix…
Basically, it's constantly checking if the player is on X spot on X map every 0.X seconds…
How would I fix this?

My suggestion is to have it ONLY check, when they move. Example : If they move the up arrow, it then checks the X spot. Also, make an array, call it a buffer. Then the characters you have on your screen, have it all get put into the buffer ( array ) first. Then once its updated, then you print everything from the buffer ( array ) to the screen. This way you get rid of the flickering. And its not constantly redrawing on the screen all the time.
Tjakka5 #32
Posted 09 May 2013 - 09:30 AM
It was working until I got into the lower room.. then I got JAVA out of bound ( array ) errors.. Yea.. JAVA.. hmmmm… I was playing this in CCDesk 6.2

My guess is your constantly running a loop counter and it ran as high as it could go.

As simple as it was, it was still cool to walk around.

Keep up the good work. :D/>

Yes, thats still something I'm working on to fix…
Basically, it's constantly checking if the player is on X spot on X map every 0.X seconds…
How would I fix this?

My suggestion is to have it ONLY check, when they move. Example : If they move the up arrow, it then checks the X spot. Also, make an array, call it a buffer. Then the characters you have on your screen, have it all get put into the buffer ( array ) first. Then once its updated, then you print everything from the buffer ( array ) to the screen. This way you get rid of the flickering. And its not constantly redrawing on the screen all the time.

Well, for now Im doing this:


for i = 1, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 do
  --code
end

And everytime the player opens the menu, the I resets…

Should be enough time?
TorakTu #33
Posted 09 May 2013 - 09:34 AM
Well, for now Im doing this:


for i = 1, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 do
  --code
end

And everytime the player opens the menu, the I resets…

Should be enough time?

That explains why your ARRAY is going out of bounds. Study up on how large an integer can hold. It can't hold that large of a number. Do as I suggested in the above post and you wont have this problem.
Tjakka5 #34
Posted 09 May 2013 - 09:59 AM
Well, for now Im doing this:


for i = 1, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 do
  --code
end

And everytime the player opens the menu, the I resets…

Should be enough time?

That explains why your ARRAY is going out of bounds. Study up on how large an integer can hold. It can't hold that large of a number. Do as I suggested in the above post and you wont have this problem.

I mean I used that to FIX the problem :P/>
Before, I was just doing a While loop, and this seems stable..

EDIT: Aaand, the thing that is getting that error is the function that constantly checks for EVERYTHING: Movement, leveling up, tping, loading, ETC
TorakTu #35
Posted 09 May 2013 - 10:06 AM
EDIT: Aaand, the thing that is getting that error is the function that constantly checks for EVERYTHING: Movement, leveling up, tping, loading, ETC

Which is why I said to have it do that ONLY when they actually move. When they hit the arrow key, it then checks.. then it sits and waits until they hit another key, and so on and so on.
theoriginalbit #36
Posted 09 May 2013 - 10:11 AM
The java out of bounds exception is something that comes from LuaJ and is commonly raised when the program stack as been filled with function calls. The common cause of this particular error is the use of recursion in the place of a simple loop.
TorakTu #37
Posted 09 May 2013 - 10:13 AM
The java out of bounds exception is something that comes from LuaJ and is commonly raised when the program stack as been filled with function calls. The common cause of this particular error is the use of recursion in the place of a simple loop.

Yea I agree… I made this simple text picture diagram to give an idea of what i'm speaking about. IF key pressed is what I meant to put in this picture.. but you should get the idea.

Spoiler
Tjakka5 #38
Posted 09 May 2013 - 10:32 AM
EDIT: Aaand, the thing that is getting that error is the function that constantly checks for EVERYTHING: Movement, leveling up, tping, loading, ETC

Which is why I said to have it do that ONLY when they actually move. When they hit the arrow key, it then checks.. then it sits and waits until they hit another key, and so on and so on.

So a mob would only move when the player moves?
I wouldnt want that…
theoriginalbit #39
Posted 09 May 2013 - 10:42 AM
Use an update timer.

This is a model I follow with most of my games (sadly not all, because it depends on how quickly I want to get it out of the way, or how lazy I'm feeling)

-main game loop-
infinitely loop
call the user input function
call the update game function
call the render game function
^ loop

-then in the user input-
detect keys, have a timeout so it doesn't get stuck on the pull event
set some flag and save the action to perform

-in the update-
move any of the NPC's or other entities in the game
perform the action that was saved from input if required and then null out the action
if something was updated set a render required flag

-render function-
if the render required flag is not set then don't do anything (this reduces flicker, why render if we don't need to!)
render the game objects, using a screen buffer here reduces flicker even more
TorakTu #40
Posted 09 May 2013 - 10:42 AM
EDIT: Aaand, the thing that is getting that error is the function that constantly checks for EVERYTHING: Movement, leveling up, tping, loading, ETC

Which is why I said to have it do that ONLY when they actually move. When they hit the arrow key, it then checks.. then it sits and waits until they hit another key, and so on and so on.

So a mob would only move when the player moves?
I wouldnt want that…

Like in my picture above.. You can have a mob function that constantly runs. But do not have anything print to the screen UNLESS the mob is in view of the screen. Meaning, setup a screen view range within the array itself. If the mob is within the view range, then you can print it to the screen. You can have the key function run ONLY when key is pressed and then it checks all info and updates to the screen as well.

In otherwords, don't constantly print to screen. This is what lags it and eventually crashes it. Only print to screen when needed.
Tjakka5 #41
Posted 09 May 2013 - 10:55 AM
Are you guys sure that you have looked trough my code?
All you are saying looks similair to what I did, or It wouldnt work with how I did it, unless I recode everything…

Anyways, that For loop seems to work, and I will definatly only print the map when a update occurs…

EDIT: Here is version 1.0.1, try to find some bugs :)/>
http://pastebin.com/mV94veBL
Tjakka5 #42
Posted 13 May 2013 - 12:51 PM
Since this forum doesnt always work for me, I will soon make a auto updater….
Tjakka5 #43
Posted 15 May 2013 - 03:27 PM
Humpediebumpriedumdum?
Tjakka5 #44
Posted 01 June 2013 - 01:20 PM
Just to bumb this old thread with some new info…


This game is currently on a hold, as I am very bussy lately as of school, and I just dont feel like programming this thing now.
I am going to program other things, maybe a OS, im not sure yet, but this thread will be reposted later when there is another big update, and for now, I consider this thread closed/dead.