Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 439 440 [441] 442 443 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 903490 times)

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6600 on: November 13, 2014, 12:51:58 pm »

I'm getting worried, I haven't been able to actually find a function to get the length of the array...

http://tibasic.wikia.com/wiki/List
http://tibasic.wikia.com/wiki/Dim(
Seems to be Dim()

Looks like you can also alter the length of the array with it
Oh hey, that's a pretty neat trick.
Now my program will be slightly less absymally slow, yay!
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Aptus

  • Bay Watcher
  • Indeed ôo
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6601 on: November 15, 2014, 04:58:41 am »

Anyone who has used TK for Ruby? I'm running into some weird scoping issues with a canvas object and a button.

Basically I create a canvas object where you can draw and do stuff.

Code: [Select]
    @workArea = TkCanvas.new(@root) do
    background 'white'
    height 300
    width 300
    pack('side' => 'top', 'pady' => 15)
    end

I then create a button which clears the canvas as so
Code: [Select]
    TkButton.new(@controls) do 
      text "Clear Vertices" 
      command { clearWorkArea() } 
      pack('side'=>'left', 'padx'=>15, 'pady'=>5) 
    end

Code: [Select]
def clearWorkArea()
@gui.workArea.delete('all')
end
@controls is a TkFrame appended to @root (it holds several buttons).

However when I click the button I get a NoMethodError, but if I call that function from anywhere else it works. I know there is just something silly I am doing wrong but I could use a pointer.

EDIT: Hmm yeah, seems to be a scoping error indeed, p self should return main but returns TK_Button instead. Interesting.
EDITEDIT: Declaring the gui as a classvariable with @@gui makes the code work, however that throws a bazillion warnings of class variable access from top level and is ugly as hell... Fuck it, works well enough for my purposes. Can always fix later.
« Last Edit: November 15, 2014, 06:00:52 am by Aptus »
Logged

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6602 on: November 15, 2014, 06:19:21 am »

I'm trying to make a Mario clone on my TI-84 during math and physics.
Problem is, TI lists aren't actually lists, they're arrays.

The enemies here should, obviously, move around, but looping through the entire matrix (I'm using 16x8 matrices as the levels) every "turn" would be far too slow. I thought of using a list (three lists, actually. Ypos, xpos and direction) of creatures instead, but that's obviously hard if I can't just add elements to the list. Any ideas?

Back when I was in high school I made Snake on my graphing calculator, then I upgraded it to have different shaped levels with different high scores for each.  I was really bored in health class.

If by clone you don't literally mean clone, I would just pick a set amount of enemies (say, 5), and then you'll always know the number of enemies AND you won't take very long each tick cycling through the list.  Each time a "new" enemy appears on the right side of the screen, pick the oldest enemy and change its location and type to the new enemy.  Since Mario games don't scroll backwards and the enemies only move forward in predictable ways, if you space out the enemies enough you'll never need to despawn a visible enemy to spawn a new one.

KISS.  After all, you're working with a calculator.
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6603 on: November 15, 2014, 07:31:13 am »

I'm trying to make a Mario clone on my TI-84 during math and physics.
Problem is, TI lists aren't actually lists, they're arrays.

The enemies here should, obviously, move around, but looping through the entire matrix (I'm using 16x8 matrices as the levels) every "turn" would be far too slow. I thought of using a list (three lists, actually. Ypos, xpos and direction) of creatures instead, but that's obviously hard if I can't just add elements to the list. Any ideas?

Back when I was in high school I made Snake on my graphing calculator, then I upgraded it to have different shaped levels with different high scores for each.  I was really bored in health class.

If by clone you don't literally mean clone, I would just pick a set amount of enemies (say, 5), and then you'll always know the number of enemies AND you won't take very long each tick cycling through the list.  Each time a "new" enemy appears on the right side of the screen, pick the oldest enemy and change its location and type to the new enemy.  Since Mario games don't scroll backwards and the enemies only move forward in predictable ways, if you space out the enemies enough you'll never need to despawn a visible enemy to spawn a new one.

KISS.  After all, you're working with a calculator.
Eh, I don't think I can realistically fit a lot of enemies on a 16x8 screen. And it'd lag to shit anyway. It's probably already lagging to shit but there's no way for me to know since I haven't actually implemented the PC yet. (SOME lag is good though, if it's too fast it will look even more like ass because the screen has an awful refresh rate)
The fun part about this will be that the levels are matrices, so you can design your very own levels (when you reach the left side of a screen it will load another matrix into matrix [A]). Requires some flexibility and overhead in the level loading, but well worth it because I have no idea where else I'd keep the levels.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6604 on: November 15, 2014, 04:33:25 pm »

Why would you need dynamic lists for a Mario clone? Mario didn't use anything like that.

Make a creature array or matrix, set it to the max. onscreen enemies (20 maybe), have 1 flag for active, others for type and x/y location. Loop through that array each frame and render them. Basically nobody used to use dynamic lists until PCs came along with lots of memory and fast CPUs.

If you're doing something with a really limited RAM/CPU system then you need to learn from how people did things on old 80's systems. The old methods were focused on raw performance and packing the most into the least memory. The new methods (like OOP, lists etc) are focused on ease of development, sacrificing raw performance.
« Last Edit: November 15, 2014, 04:47:49 pm by Reelya »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6605 on: November 15, 2014, 04:40:36 pm »

Yeah, stuff like that is why SMB1 couldn't scroll backwards.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6606 on: November 15, 2014, 04:43:28 pm »

I understand that, and if I were writing this in assembler, that is what I would do. (maybe in Calculator Q 3)
However, I am using the slowass TI-BASIC interpreter that comes with the calculator.

And this overhead only applies when loading a new "level". This is certainly not done every tick, that'd be insane.
This solution improves the speed of each tick, in fact, since it saves on having to loop through empty entries in the list.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6607 on: November 15, 2014, 04:53:26 pm »

With arrays you don't have to scan empty entries. Say "max" is 20 enemies, but the current level has 10. You just store the current enemies in the first 10 positions and have a value "current_max" for this level, and loop up to that. Hence it's still faster than scanning 10 list items, since you don't have to look up and dereference the "next" pointer for each entry, you just increment the index.

And if you want to "skip" dead enemies, you can have an extra array field called "next" to emulate list functionality. You'll have to write the code for correctly setting the "next" pointer when an enemy dies yourself though. Another method, which is actually easier to implement, is to copy the data for the last alive enemy into the index of the dead enemy, and subtract 1 from "current_max". To dynamically add an enemy, increment current_max by one and store the data there. That's less hassle than trying to have "next" pointers, and will make the looping a lot faster.

Arrays done properly = win/win on both memory and speed. Game programmers already solved any problem you can mention 30+ years ago. People who are looping through empty array items just have poorly-written unoptimized code.
« Last Edit: November 15, 2014, 06:55:56 pm by Reelya »
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6608 on: November 15, 2014, 04:57:29 pm »

I cannot choose between lists and arrays. There is only one data structure, called a list. However, I need to explicitly define it's size, so I'm not sure exactly what it is.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6609 on: November 15, 2014, 04:58:26 pm »

You can tell what it is by the set of operations they allow. My money is on an array though. Set size, limited RAM. Only an array makes sense.

But what I meant was you CAN choose: people in the 80's implemented everything you can imagine in basic or assembler without "built-in" data structures. Effectively, RAM is an array, and lists are a higher-level structure imposed on that array. You can implement "list functionality" inside an array basically - you just have fields for "next index" and/or "prev index" and write the code for handling this yourself. Whatever building blocks they give you and whatever name they give them, you implement functionality as a solution. So don't get too stuck on what they "give" you.

But read my last post for my suggestion of the best way to handle a creature array (I bolded the important details).
« Last Edit: November 15, 2014, 05:06:22 pm by Reelya »
Logged

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #6610 on: November 16, 2014, 02:45:14 am »

Check these SQL for me?

Spoiler: Goals (click to show/hide)

Code: (1) [Select]
CREATE PROCEDURE test()
BEGIN
     DECLARE sql_error TINYINT DEFAULT FALSE;

     DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
          SET sql_error = TRUE;

     START TRANSACTION;

     DELETE FROM Customers
          WHERE customer_id = 8

     IF sql_error = FALSE THEN
          COMMIT;
          SELECT ‘The transaction was committed.’;

     END IF;
END//

Code: (2) [Select]
CREATE PROCEDURE test()
BEGIN
     DECLARE sql_error TINYINT DEFAULT FALSE;

     DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
          SET sql_error = TRUE;

     START TRANSACTION;

     INSERT INTO orders VALUES
     (DEFAULT, 3, NOW(), '10.00', '0.00', NULL, 4,
     'American Express', '378282246310005', '04/2013', 4);
 
     SELECT LAST_INSERT_ID()
     INTO order_id;
 
     INSERT INTO order_items VALUES
     (DEFAULT, order_id, 6, '415.00', '161.85', 1);
 
     INSERT INTO order_items VALUES
     (DEFAULT, order_id, 1, '699.00', '209.70', 1);
 
     IF sql_error = FALSE THEN
          COMMIT;
          SELECT ‘The transaction was committed.’;

     END IF;
END//
Logged

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6611 on: November 17, 2014, 06:35:33 am »

Check these SQL for me?

You missed this:

Quote
1. Write a script that creates and calls a stored procedure named test. This procedure should include two SQL statements coded as a transaction to delete the row with a customer ID of 8 from the Customers table. To do this, you must first delete all addresses for that order from the Addresses table.

2. Write a script that creates and calls a stored procedure named test. This procedure should include these statements coded as a transaction:

[...]
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

Dutrius

  • Bay Watcher
  • No longer extremely unavailable!
    • View Profile
    • Arcanus Technica
Re: if self.isCoder(): post() #Programming Thread
« Reply #6612 on: November 17, 2014, 12:22:59 pm »

Hellooooooo!

Pascal user here!
Logged
No longer extremely unavailable!
Sig text
ArcTech: Incursus. On hold indefinitely.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6613 on: November 17, 2014, 03:35:59 pm »

Eww. Haven't touch pascal in a long time. What are the selling points for that vs just using c?

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6614 on: November 17, 2014, 03:37:51 pm »

I do like how the Wikipedia article opens up by calling it "formerly influential".
Pages: 1 ... 439 440 [441] 442 443 ... 796