Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2d Boolean Array

 
DANIEL GRESHAM
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fisrt of all forgive my ignorance, I'm only 5 weeks in on the language.
Im working on a 2d Boolean array that is represented as an imaginary floor, when moving my "rat" across the floor(also the name of the array), I need to be able to leave a trail if it is toggled by the user. almost all of the coding is done but I do not know how to return a Boolean value into a "floor space" as I travel across it can someone just give me a general idea of how to place a boolean value of true onto a 2d array that is already default as false? please do not give me the complete answer, just a gental kick in the right direction.
thanx
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
array[x][y] = true; usually does the trick.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Daniel -

If I understand what you're looking for, a simple assignment should do the trick. Because you capitalize Boolean, I'm assuming you are using Boolean objects, not primitive data types. You can't modify a Boolean object because the fields are final and there are no setter methods anyway. If you have an array of rows and objects, then you could create a new Boolean with the desired value and assign it to the array element you need to change.

Hope that helps...
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would probably be easier to use the boolean primitive rather than the Boolean wrapper class. In such a case, an assignment will do the job of toggling the value.

Layne
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very true, but if the professor wanted an array of Boolean objects and the student uses an array of boolean primitives, guess what the grade will be!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic