This site requires JavaScript, please enable it in your browser!
Greenfoot back
iWin4Poland
iWin4Poland wrote ...

2012/10/20

Need help with working across classes

iWin4Poland iWin4Poland

2012/10/20

#
I'm trying to make a program which its classes look like this(code is not of importance yet) I want basically if i press drum_1 to go to the tune class and find its corresponding sound and play it. afterwards check if a boolean within the record class is true or false and if it is true i want to assign a certain value in the list depending on the which drum_x i press. Help is really appreciated :) i'm trying to figure out since days but i havent gotten any step further :)
danpost danpost

2012/10/20

#
What part are you working on now? and, in what way are you having a problem with it? also, what code have you tried (code is very important)?
iWin4Poland iWin4Poland

2012/10/20

#
I am trying to working on the record function. My problem is that i don't know how i can access one class from another for example: If i press on drum_1 it should play a sound. i should go afterwards to the record class (problem #1) check if record is toogled on or off assign 1 at a certain position in a list(problem #2, no experience with list) if its on
danpost danpost

2012/10/20

#
First, let me say that there must be one Record object created and in your world (this probably should be done at world construction). The Record class needs to have an instance boolean variable to track whether recording is on or not (can be called something like 'recordingOn'). You can add a method in the Record class to return the value of 'recordingOn'.
public boolean getRecordingState()
{
    return recordingOn;
}
Now your other classes can access its value with
// from another actor class
boolean recording = ((Record) getWorld().getObjects(Record.class).get(0)).getRecordingState();
// from a world class
boolean recording = ((Record) getObjects(Record.class).get(0)).getRecordingState();
As far as lists go, you are going to be listing values of 1s and 2s. Since they are both one-digit numbers, you could easily list them in a String (i.e. "122112221212111"). If you want rests added in, use the space (" ").
iWin4Poland iWin4Poland

2012/10/20

#
nice that helped me a lot :) Is there a command like there is in vba to read a certain location in the string such as the 3rd position. Since i want later the recorded thing to be playable EDIT: i tried to make it work to go from my drum_1 method to the tone method but it i can an error expression which i don't really know how to solve. EDIT2: I canged boolean a = false; to byte a;
danpost danpost

2012/10/21

#
You can find the methods you can use on String objects here.
You need to login to post a reply.