ID:165848
 
How would i change var information in game like lets say i want to draw power from a powergenerator and move it to the shield generator

I've tyied something like this but i can't seem to get it
        Shield_Console
icon='Shield.dmi'
icon_state="SC"
var/active=0
verb/Activate()
set src in oview(1)
if(var/obj/electrionics/power_generator/power>=10000)


Or am i on the wrong track?
Yorae wrote:
            if(var/obj/electrionics/power_generator/power>=10000)
>

Or am i on the wrong track?

Yes, but you are close. I'll try to explain it, but I am in class and we're about to leave for lunch.

In object-oriented programming, what you need is to draw the distinction between classes and objects. A class would be the definition of a certain something; in this case the class would be your power_generator. The objects are individual instances of the class.

When comparing data from the class, you want to compare data from an object itself. In this case, what you want to do is to create an instance of /obj/electronics/power_generator, and create a variable to hold a reference to this particular instance. Then you would access variables from this reference:
var/obj/electronics/power_generator/thePG = new
world << "The Power Generator has a power value of [thePG.power]!"

This particular example assumes that the class definition for /obj/electronics/power_generator has a variable named power.

Hiead
In response to Hiead
if you only have 1 of each then create a global variable that is = to the object
otherwise you can scan through the world to find the one u need and set that to a variable! orrrrr, set mob variables if each player gets one, the way he showed would work, but it would create a new generator every time
In response to Falacy
Yes but i would still like to know how it would be be done anyway because there are many other parts that i'm working on that would require that same thing. Like power_generator draws power from something.
In response to Yorae
what o.O we just explained things o.O
In response to Falacy
Sorry but i don't get it.
In response to Yorae
var/obj/generators/power
var/obj/generators/shield

world
New()
power=new/obj/generators/power_generator(location)
shield=new/obj/generators/shield_generator(location)

obj
generators
var/energy=10000
shield_generator
verb/Shift_Power()
src.energy-=1000
power.energy+=1000
power_generator
verb/Shift_Power()
src.energy-=1000
shield.energy+=1000
In response to Falacy
That would work in a way but i already have programmed a power source but the problem is when i place it inside the power_generator and i active it i can't draw power from it thats what i mean.

For example the power sources power is drawed into the generator and then is distributed across the ship.
In response to Yorae
hrm, so you have a seperate power item that you place inside the generator to give it power?
and then you want to distribute that power? automaticaly or by player input?
In response to Yorae
Yorae wrote:
Sorry but i don't get it.

Have you read the DM Guide? It's a vital resource that's essential for budding BYOND developers.

While you read that, I suggest you take a look at some DM Demos. I recommend Dantom's "Your First World" and Deadron's "Step BYOND". Of course, you should read the code for meaning, and read the comments to learn. Attempting to copy|paste anything will not get you very far at all.

Hiead
In response to Hiead
Hiead wrote:
Yorae wrote:
Sorry but i don't get it.

Have you read the DM Guide? It's a vital resource that's essential for budding BYOND developers.

While you read that, I suggest you take a look at some DM Demos. I recommend Dantom's "Your First World" and Deadron's "Step BYOND". Of course, you should read the code for meaning, and read the comments to learn. Attempting to copy|paste anything will not get you very far at all.

Hiead

I've read the DM Guild i've looked though reference. I've also looked for a demo on this but to no luck there isen't one.

hrm, so you have a seperate power item that you place inside the generator to give it power?
and then you want to distribute that power? automaticaly or by player input?

I've already created it to generate power but my problem is moving it to another objs var.
In response to Yorae
for(var/obj/shield_generator/O in world)
O.energy+=1000

something like that maybe... dont really know how u have things setup
In response to Falacy
Thanks for the help guys i figured it out and a bit more.