Jump to content




[QUESTION] Mouse input for more than one spot?


58 replies to this topic

#41 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 12 April 2013 - 05:35 AM

If you call this, learning than you should learn how to learn, things :D
Below you find some quotes of you from this topic, below i give you the reaction and answer of someone who wants to learn sth.
maybe you can learn sth from this, if not then not maybe it makes someone smiling.

Spoiler

sorry for bad grammar and spelling im just a German :D
And take it with a twinkle in one eye and not as offense ;)

so far
Loki

#42 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 12 April 2013 - 05:53 AM

View PostMackan90096, on 12 April 2013 - 04:29 AM, said:

Well.. In that case i would like to "learn to fish" xD

And i'll release the game in two "versions". In my OS and a "stand-alone".

Oh, smiley, Where do I put this and how do I format it to work?

	 if  x >= 1 and x <= 11 and y == 7 then
		if money == multiCost then
			multiCost = multiCost*2
			  multi = multi+1
		end
	 end

It's for the multiplier upgrade,

thats a good step in the learning direction :)

cause i am still learning too im not sure if this works (minecraft does not let me work at the moment :))
but i put your code into the code of Smiley and added comments so you see where i put it and what was not good

look at the functions section where i added buymultiply
User Data where i added the multiplier costs
And the ------------ Running Code --------
where i added the code to check if you clicked the position for buying the multiply



http://pastebin.com/QxapKeV8

#43 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 12 April 2013 - 06:53 AM

View Posttheoriginalbit, on 10 April 2013 - 08:43 PM, said:

If you do it in an Object-Oriented way it will mean that you wont have to have heaps of identical code. you can just loop through all the pixels and 'ask' if they have been clicked with a function like wasClicked or something of the such...
you dont need OOP to loop though a table .-.

#44 Smiley43210

  • Members
  • 204 posts

Posted 12 April 2013 - 06:59 AM

View PostPixelToast, on 12 April 2013 - 06:53 AM, said:

you dont need OOP to loop though a table .-.
True, but thats kinda the way we've done it. And if you use a function to add a table of data about one 'pixel' to a main table that holds all of such, isn't that kinda OOP?

#45 Mackan90096

  • Signature Abuser
  • 518 posts
  • LocationIn my basement.

Posted 12 April 2013 - 07:00 AM

Well... Lord...
Thank you for helping me..
There are some emulators that you could use to test CC things.

Edit: The upgrade button wont work :(

Pastebin for the .game1 bar: http://pastebin.com/ZMEq47tM

And my current code: http://pastebin.com/D9FRW0Gy

Edit (Again, yes)
It does work.. But it doesn't show up until you click a gem after..

More edits! (xD)

The button doesn't work properly... :(

#46 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 12 April 2013 - 07:13 AM

View PostSmiley43210, on 12 April 2013 - 06:59 AM, said:

View PostPixelToast, on 12 April 2013 - 06:53 AM, said:

you dont need OOP to loop though a table .-.
True, but thats kinda the way we've done it. And if you use a function to add a table of data about one 'pixel' to a main table that holds all of such, isn't that kinda OOP?
then everything in lua would be OOP
i dont want to continue this, the last thread discussing OOP went down the toilet

#47 Smiley43210

  • Members
  • 204 posts

Posted 12 April 2013 - 07:25 AM

Updated both programs to reflect changes (can't test thought cause I'm at school)

Normal version:
http://pastebin.com/JNDK2ZKV
Debug version:
http://pastebin.com/h0nepPn7

#48 Mackan90096

  • Signature Abuser
  • 518 posts
  • LocationIn my basement.

Posted 12 April 2013 - 07:31 AM

Smiley.. Lord's version work better honestly..

But not as I want it to xD

Current code:

-- Change absolutely whatever you need to, even if it says you shouldn't

gamebar = paintutils.loadImage("/sprites/bars/.game1")
------------ General Settings ------------

------ Required Internal ------
-- Changing anything in this section isn't recommended
local width, height = term.getSize() -- Must be defined before Gem Settings

------ Gem Settings ------
-- The number of gems to have on the screen at all times
local gemsOnScreen = 10
-- The minimum x coordinate that a gem can be generated at
local minX = 13
-- The minimum y coordinate that a gem can be generated at
local minY = 4
-- The maximum x coordinate that a gem can be generated at
local maxX = 47
-- The maximum y coordinate that a gem can be generated at
local maxY = height - 1
-- List of possible gem colors
local colorChoices = { colors.purple, colors.yellow, colors.lime, colors.lightBlue }
-- Define the gem worth value (money received when clicked)
local gemValue = { }
gemValue[colors.purple] = 10 -- Get 10 money when you click a purple gem
gemValue[colors.yellow] = 5 -- Get 5 money when you click a pink gem
gemValue[colors.lime] = 15 -- Get 15 money when you click a lime gem
gemValue[colors.lightBlue] = 20 -- Get 20 money when you click a blue gem

------ Screen Settings ------
-- Background color
local bgColor = colors.red
-- Text color
local txtColor = colors.white

------------ Internals ------------

------ User Data ------
local money = 0
local gemsClicked = 0
local multi = 1
local multiCost = 100 -- add new variable for multiCost

------ Gem Data ------
-- Table that stores the pixel data (coordinates and color)
local gems = { }

------------ Functions ------------

local function buymultiply() -- make a function out of it so you can use it where you need it  
if money >= multiCost then  -- should be > else you only can buy it when you have exactly this amount
multiCost = multiCost*2
 multi = multi+1
 money = money - multiCost
end
end

function newGem()
    local w, h = term.getSize()
    local x, y

    -- Pick a random spot for the pixel to appear
    while true do
        x = math.random(minX, maxX) -- Random number for the x coordinate
        y = math.random(minY, maxY) -- Random number for the y coordinate
        if #gems > 0 then
            local good = true
            for i, v in ipairs(gems) do
                -- Check to see if a gem already exists in that position
                if v[1] == x and v[2] == y then good = false end
            end
            if good then break end
        else
            break
        end
    end

    -- Now, we choose a random color for the pixel (maybe you don't need this)
    local color = colorChoices[math.random(1, #colorChoices)]

    -- This holds the coordinates and the color of the gem
    local gem = {x, y, color}
    table.insert(gems, gem) -- Adds the gem data to the main table

    -- Draw the gem
    term.setCursorPos(x, y)
    term.setBackgroundColor(color)
    write(" ")
    term.setBackgroundColor(bgColor)
end

function spawnGems(n)
    for i = 1, n do
        newGem()
    end
end

function stats()
    paintutils.drawImage(gamebar, 1,1)
    term.setCursorPos(1,1)
    -- You don't need term.setCursorPos(1, 2) since print automatically moves a line down each time
    print("Money: "..money)
    print("Gems: "..gemsClicked)
    print("Multiplier: ")
    print(multi.."x")
    print("")
    print("Upgrades:")
    print("Multiplier")
    print("Price:")
    print(multiCost)
end
------------ Running Code ------------

-- Don't use a number for the color unless absolutely nessecary...and I have no idea when it would be
-- Use the colors API. 16384 is the same as saying colors.red
term.setBackgroundColor(bgColor)
term.setTextColor(txtColor)
term.clear()
spawnGems(gemsOnScreen)
stats()

while true do
    local e, p1, p2, p3 = os.pullEvent("mouse_click")
    -- Check if the coordinates clicked are any of the pixel's coordinates
if  p1 >= 1 and p1 <= 11 and p2 == 7 then  -- im not sure about this but i thik this should work cause needs to be checked after click and has to be outside the loop for getting gemcoords
buymultiply()
end
    for i, v in ipairs(gems) do
        if p1 == 1 and v[1] == p2 and v[2] == p3 then -- A gem was LEFT clicked
            -- Do stuff here
            -- Do more stuff
            -- Increment variables
            gemsClicked = gemsClicked + 1

            -- Give money
            money = money + (gemValue[v[3]] * multi) -- Gem value multiplied by the multiplier

            -- Remove the gem
            term.setBackgroundColor(bgColor)
            term.setCursorPos(v[1], v[2])
            write(" ")
            table.remove(gems, i)

            -- Spawn a new gem
            newGem()

            -- Update stats
            stats()
        end
    end
    sleep(0.05)
end

It should when the upgrade multiplier button, remove the cost of it from the money and print the new multiplier value.

#49 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 12 April 2013 - 09:03 AM

will check it and give you feedback :)

#50 Smiley43210

  • Members
  • 204 posts

Posted 12 April 2013 - 09:25 AM

View PostMackan90096, on 12 April 2013 - 07:31 AM, said:

-snip-
It should when the upgrade multiplier button, remove the cost of it from the money and print the new multiplier value.
It should...double checking...

Fixed problem in click detection (copy/pasted the pseudo code and forgot to change var names)
Updated upgrade 'store' with your design
Fixed taking twice as much money for the multiplier upgrade
Removed debug code from the non-debug one that made marks on side(I left some in by accident)

#51 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 12 April 2013 - 10:29 AM

hehe smiley we are such coding monkeys :D

i updated too made it so that upgrade option shows up in the top right corner when you have enough money

http://pastebin.com/QxapKeV8

fixed some small things i forgot to change back

Edited by LordIkol, 12 April 2013 - 10:37 AM.


#52 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 12 April 2013 - 10:49 AM

View PostLordIkol, on 12 April 2013 - 10:29 AM, said:

hehe smiley we are such coding monkeys :D
Just be aware, if you do all the work for them, they almost never learn how to do it themselves. However, if you insist on being 'coding monkeys' be sure to comment each, and I mean each, line so the user knows what that line does.

#53 Smiley43210

  • Members
  • 204 posts

Posted 12 April 2013 - 04:28 PM

View PostSuicidalSTDz, on 12 April 2013 - 10:49 AM, said:

View PostLordIkol, on 12 April 2013 - 10:29 AM, said:

hehe smiley we are such coding monkeys :D
Just be aware, if you do all the work for them, they almost never learn how to do it themselves. However, if you insist on being 'coding monkeys' be sure to comment each, and I mean each, line so the user knows what that line does.
Yeah, I'm aware of that.

#54 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 12 April 2013 - 05:32 PM

View PostSuicidalSTDz, on 12 April 2013 - 10:49 AM, said:

View PostLordIkol, on 12 April 2013 - 10:29 AM, said:

hehe smiley we are such coding monkeys :D/>
Just be aware, if you do all the work for them, they almost never learn how to do it themselves. However, if you insist on being 'coding monkeys' be sure to comment each, and I mean each, line so the user knows what that line does.

You can not teach people who are not willing to learn. (See spoiler above)
But i like the Idea of the Game and im learning from this too so everything is fine.
And about the comments,i will update code with some more comments, thats a good advice

#55 Smiley43210

  • Members
  • 204 posts

Posted 12 April 2013 - 06:47 PM

Seems like he wants to learn, and it looks like he's learning.

"All is not what it seems" :P
Jk

#56 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 12 April 2013 - 08:20 PM

View PostSmiley43210, on 12 April 2013 - 06:47 PM, said:

Seems like he wants to learn, and it looks like he's learning.

"All is not what it seems" :P
Jk

Muhaha well spoken :D
i think we gave him a good base to work with.
When im back Home i will add some comments in my code paste some sources for him to learn and than he can show his will and ability to learn :D
Enough Coding Monkeyness for me, but maybe i will work on on the game on my own if i get bored at weekend think you could make something funny of this if you put some work into

edit: grats to post number 100, you are not a Kiddie anymore :D :D
so far Loki

#57 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 13 April 2013 - 12:45 AM

View PostLordIkol, on 12 April 2013 - 08:20 PM, said:

View PostSmiley43210, on 12 April 2013 - 06:47 PM, said:

Seems like he wants to learn, and it looks like he's learning.

"All is not what it seems" :P/>
Jk

Muhaha well spoken :D/>
i think we gave him a good base to work with.
When im back Home i will add some comments in my code paste some sources for him to learn and than he can show his will and ability to learn :D/>
Enough Coding Monkeyness for me, but maybe i will work on on the game on my own if i get bored at weekend think you could make something funny of this if you put some work into

edit: grats to post number 100, you are not a Kiddie anymore :D/> :D/>
so far Loki
This is obviously not a situation in which all the work is being given to the user. Disregard my last comment.

Good job ^_^

#58 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 13 April 2013 - 01:53 AM

Hehe look at the last post i made on page 2 and especially first post i made on this page, then you see im not willing to be a coding monkey for people who are not willing to put work in on their own :D
but the Idea is nice as has potential so i worthship this idea with a code and some info to get it running :)

Greets
Loki

#59 Smiley43210

  • Members
  • 204 posts

Posted 13 April 2013 - 08:19 AM

View PostLordIkol, on 13 April 2013 - 01:53 AM, said:

Hehe look at the last post i made on page 2 and especially first post i made on this page, then you see im not willing to be a coding monkey for people who are not willing to put work in on their own :D
but the Idea is nice as has potential so i worthship this idea with a code and some info to get it running :)

Greets
Loki
Same for me, as you could see, if you have seen some other posts I've made in other topics.
Hey the beginning rhymes :D

Oh and ty lord (for the grats)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users