#How do i make an int public?

67 messages · Page 1 of 1 (latest)

lost quartz
#

I am trying to make an integer accessable to multiple methods, but it always sais the variable doesn't exist. I made the variable "cash" in void setup, and i want to know how i can access it in other voids.

tough summitBOT
#

This post has been reserved for your question.

Hey @lost quartz! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

tardy cargo
#

that variable would have to be a instance or static field rather than local

lost quartz
#

and how do i make that?

tardy cargo
#

see there ^

lost quartz
#

i don't really understand what's written there

#

i'm trying to solve this

#

basically i declared the int cash in void setup

#

and now i want to change it in void clock

#

how do i do that?

tardy cargo
pure parrot
#

Looks like processing. I'm not sure the syntax for field variables

lost quartz
#

it is processing 4.1.1

pure parrot
#

You're sort of supposed to say that. This is a Java server, not a Processing server. Processing isn't Java

lost quartz
#

wait what?

#

but i'll say it next time, sorry

pure parrot
# lost quartz our teacher said it's java

I hear it's very close. But it is not Java. In Java everything must be in a class or other type definition. In processing it looks like you define methods in the middle of nowhere

#

(Which technically would make them functions, not methods)

lost quartz
#

that's weird

#

but if it's not ordinary java, that explains why 98% of what i find on the internet won't work i guess

pure parrot
#

indeed

lost quartz
#

so, how do i get my problem solved then?

tough summitBOT
# lost quartz so, how do i get my problem solved then?

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

pure parrot
#

You're going to need someone who knows processing I'm afraid

lost quartz
#

damn

#

i've literally got 2 days to finish this

tardy cargo
#

what if you declare it outside the methods

lost quartz
#

i could try that

#

wait i think that's how it works

#

why do i always forget the important things!?

#

it works

#

but instead of adding to the cash counter every 2 seconds (30 fps, should update/increase every 60 frames) it just goes up and up at the speed of sound

#

does processing update variables every frame?

tardy cargo
#

your clock isn't actually waiting for anything

#

it just counts to 60, without waiting for a frame to pass before incrementing

#

what even is the point of your for loop there? it's essentially an infinite loop, but it tracks a variable i meaning it breaks once it reaches 2.1B

lost quartz
#

i just wanted to make a clock to increase cash every 60 frames, and the solution i was given by another person on here was that kind of for loop

tardy cargo
#

you have to wait for a frame to pass

lost quartz
#

how do i do that?

tardy cargo
#

idk, that's kinda specific to processing

#

also, counting frames isn't a great way to maintain a clock, lower-end devices will still be able to run at fps < 30

lost quartz
#

dang guess I'll either have to find someone who knows processing or find something on Google

lost quartz
tardy cargo
#

that's not what i mean

#

counting frames to maintain a clock is a bad idea in general

lost quartz
#

how do i do it then?

tardy cargo
#

checking actual time

lost quartz
#

all i found on google involved librarys and other shit i don't understand

#

and won't understand as my time is running out

tardy cargo
#

no libs korone_korofused

lost quartz
#

oh

#

that makes things easier

#

thanks

tough summitBOT
# lost quartz thanks

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

tardy cargo
lost quartz
#

now i'll try to create something passable in the day i have left

#

and pray that my teacher will somehow not be a dick

#

but without that it'd be impossible, thanks so much!

tardy cargo
#

seems like the draw function is called every frame/tick

#

check time there

lost quartz
#

so that's what draw is for

tardy cargo
#

or if you're ok with a bodge for now, increment a counter there

#

i have no experience with processing i literally just looked at the examples

lost quartz
#

thanks again, i didn't know those examples existed!