Home   Help Search Login Register  

Author Topic: Repairing (physically/visually)  (Read 3379 times)

0 Members and 1 Guest are viewing this topic.

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Repairing (physically/visually)
« on: 31 Mar 2008, 10:43:43 »
ok, so this is the deal

init.sqs:
Code: [Select]
evac setVehicleArmor 0.1
~100
evac setVehicleArmor 0.2
~100
evac setVehicleArmor 0.3
~100
evac setVehicleArmor 0.4
~100
evac setVehicleArmor 0.5
~100
evac setVehicleArmor 0.6
~100
evac setVehicleArmor 0.7
~100
evac setVehicleArmor 0.8
~100
evac setVehicleArmor 0.9
~100
evac setVehicleArmor 1
~100
evac setFuel .1
~100
evac setFuel .2
~100
evac setFuel .3
~100
evac setFuel .4
~100
evac setFuel .5
exit

Now, "evac" is the chopper name.

Basically, I think there is a better way to go about this. I have tried stuff like

Code: [Select]
repair = (1 - getDammage evac) <- in a loop that updates every 10sec
evac setVehicleArmor (repair +.1) <- small increments every 30sec

I am not sure if that exact code causes an error but I remember it was something close to that and did not cause any errors.

It is hard for me to understand this since I am dealing with a dbl negative.... getDammage returns 1 when vehicle is destroyed, or something like that, so I try to counter it with adding/subtracting it.... I am really just all sorts of confused in the head... lol
TS3 IP: tor.zebgames.com:9992

Offline Loyalguard

  • Former Staff
  • ****
Re: Repairing (physically/visually)
« Reply #1 on: 31 Mar 2008, 11:48:31 »
There is no need to use setVehicleArmor.  There is some confusion on the properties of it so since you can do this with setDamage I recommend avoiding it.  Try this in your loop.

Code: [Select]
if ((getDammage evac) > 0) then
{
     evac setDamage (getDammage evac - .1);
};

Change ".1" to whatever value you want to change per each step of your loop.

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Repairing (physically/visually)
« Reply #2 on: 31 Mar 2008, 20:32:00 »
ok, thanks.

setVehicleArmor does repair it too, but I guess it is buggy or something?
TS3 IP: tor.zebgames.com:9992

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Repairing (physically/visually)
« Reply #3 on: 02 Apr 2008, 07:45:00 »
Code: [Select]
_repair = false;
_refuel = false;

while(_repair == false) do
{
     evac setDamage (getDammage evac - .1);

if(getDammage evac) == 0)then
{
_repair = true;
};

~10
};

while(_refuel == false) do
{
evac setFuel +.1;

if(Fuel(evac) == .5)then
{
_refuel = true;
};

~10
};

exit

For some reason, this doesn't work. Can someone fill me in please?
TS3 IP: tor.zebgames.com:9992

Offline Loyalguard

  • Former Staff
  • ****
Re: Repairing (physically/visually)
« Reply #4 on: 02 Apr 2008, 11:41:17 »
Ok.  You had some syntax and method errors, here is how the first part of your script should look.  Check the comments for specific changes:

Code: [Select]
private ["_repair", "_refuel"]; // Introduce local variables to the innermost scope to check or change them (inside loops, etc.).

_repair = false;
_refuel = false;

while {!_repair} do // {!_repair} is a better way of writing {_repair == false}.  Also while condition must be in {} not ().
{
      evac setDamage (getDammage evac - .1);
if ((getDammage evac) == 0) then // Forgot a "(".
{
_repair = true;
};
sleep 10;
};

Copy these changes to your refuel section and you should be good to go.
« Last Edit: 02 Apr 2008, 12:27:53 by Loyalguard »

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Repairing (physically/visually)
« Reply #5 on: 02 Apr 2008, 11:49:41 »
So, I used that code but it returns an error: Type bool, expected code....
« Last Edit: 02 Apr 2008, 23:54:43 by Ironman »
TS3 IP: tor.zebgames.com:9992

Offline Cheetah

  • Former Staff
  • ****
Re: Repairing (physically/visually)
« Reply #6 on: 03 Apr 2008, 12:51:17 »
Where exactly is the error located according to the error message?

You could try to remove all the comments in the code, see if they are causing problems.
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline Loyalguard

  • Former Staff
  • ****
Re: Repairing (physically/visually)
« Reply #7 on: 03 Apr 2008, 18:31:44 »
Hmmm, I ran the code successfully with all the comments but as Cheetah suggested do remove them AND tells us exactly what the error message says.

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Repairing (physically/visually)
« Reply #8 on: 03 Apr 2008, 21:51:19 »
init.sqs:
Code: [Select]
;Initialize revive script
server execVM "revive_init.sqf";

[] execVM "repair.sqs";
exit

repair.sqs:
Code: [Select]
private ["_repair", "_refuel"];
_repair = false;
_refuel = false;

while {!_repair} do
{
     evac setDamage (getDammage evac - .1);
if ((getDammage evac) == 0) then
{
_repair = true;
};
sleep 10;
};

while {!_refuel} do
{
     Fuel evac +.1;

if ((Fuel evac) == .5) then
{
_refuel = true;
};

sleep 10;
};

exit

error msg:
Code: [Select]

Invalid number in expression

repair.sqs line 1.

TS3 IP: tor.zebgames.com:9992

Offline Loyalguard

  • Former Staff
  • ****
Re: Repairing (physically/visually)
« Reply #9 on: 03 Apr 2008, 22:21:36 »
Ah, I believe the source of the error(s) is that I have given you SQF syntax for a .sqs script.  I did not notice that your original script was SQS.  I am an SQF-only guy for the most part so I will have to leave it to someone else to convert the SQF to SQS or you can use my code as a .sqf instead of .sqs.  Sorry for the confusion!

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Repairing (physically/visually)
« Reply #10 on: 03 Apr 2008, 23:57:27 »
I can use sqf, just have been starting the transition since I know other programming languages....

So I switched it into a sqf file and it still doesn't run properly. Same error.

Can a error just get stuck in a missions? Even if there is nothing wrong?
« Last Edit: 04 Apr 2008, 00:14:22 by Ironman »
TS3 IP: tor.zebgames.com:9992

Offline Loyalguard

  • Former Staff
  • ****
Re: Repairing (physically/visually)
« Reply #11 on: 04 Apr 2008, 02:41:33 »
I have attached a demo mission using the code I posted above as an init.sqf.  Iy uses a HMMVWV named evac for testing purposes.  If you watch the windows you will see them be repaired.  The only change is that I made the sleep delay 2 secs instead of 10 in order to test it faster.  DL the mission, unzip it, and put it in your editor missions folder.  Test it in the editor and see if it works.  If not report back.  If so use it as a template to add the refuel portion
« Last Edit: 20 Aug 2009, 20:58:34 by hoz »

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Repairing (physically/visually)
« Reply #12 on: 04 Apr 2008, 05:56:05 »
ok, the real problem I am running into are spetsnatz that can run faster than normal. It almost looks like lag but it is not due. I can tell it is not lag cuz I am hosting it and I see him very smoothly running fast. (no drops in FPS)

I thought this might be occuring from the long freakin repair I had in my init file. So, I copied your code into my repair.sqf and it seems to have a problem with the Sleep command. I don't know why...

But anyways, having a loop like the one you have created for an init.sqf file is ok? Because the repair I have going on will take about 23 min to complete. Would that cause problems?

*************************
Code: [Select]
while {!_refuel} do
{
      evac setFuel (Fuel(evac)+.1);

if ((Fuel(evac)) == .5) then
{
_refuel = true;
};

sleep 100;
};

the above code is having a problem exiting out of loop after .5 is reached, any ideas?
« Last Edit: 04 Apr 2008, 06:11:28 by Ironman »
TS3 IP: tor.zebgames.com:9992

Offline Rommel92

  • Members
  • *
Re: Repairing (physically/visually)
« Reply #13 on: 04 Apr 2008, 06:49:55 »
So, I used that code but it returns an error: Type bool, expected code....

Just on the note of True or False settings, I get Type bool, expected errors a lot. To the point i can't see any use in them, 0 and 1 do just fine. The code syntax and structure is perfect, but it just doesn't work. The second I change it to while {refuel == 0} it works perfect.

(0 being false, 1 being true).

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Repairing (physically/visually)
« Reply #14 on: 04 Apr 2008, 11:39:45 »
Yea, that works thanks Rommel.

Now what would I do if I wanted to put the script in another file called repair.sqf? Would I keep the first three lines of code in the init?
TS3 IP: tor.zebgames.com:9992

Offline Loyalguard

  • Former Staff
  • ****
Re: Repairing (physically/visually)
« Reply #15 on: 04 Apr 2008, 13:58:48 »
If you change your init.sqs to init.sqf it would/should look like this:

// Initialize revive script
server execVM "revive_init.sqf";

_nul = [] execVM "repair.sqf";

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Repairing (physically/visually)
« Reply #16 on: 04 Apr 2008, 20:50:46 »
what is the _nul for?
TS3 IP: tor.zebgames.com:9992

Offline Loyalguard

  • Former Staff
  • ****
Re: Repairing (physically/visually)
« Reply #17 on: 04 Apr 2008, 22:00:37 »
_nul is what is called a "handle" and is used with the execVM or spawn commands.  It's a way of identifying a script and/or storing any return values (the latter being one of the most common uses).  It can be in the form of a global or local variable.  In the example I gave you, I designated it _nul to mark it as something from which I don't expect any return value.  You can call it anything as long as you follow the normal variable rules.  A good example of where a return might be useful using execVM is the addAction command where the handle stores the unique ID of of the action.

Offline Ironman

  • Former Staff
  • ****
    • {GSF} Home Page
Re: Repairing (physically/visually)
« Reply #18 on: 05 Apr 2008, 03:23:44 »
Ok, so the "_nul" will handle and returns that might be sent back. In this case, none will be sent.

So it is like Java's:

public void blahBlah()
{

}

where void is the return type.... right?
TS3 IP: tor.zebgames.com:9992

Offline Loyalguard

  • Former Staff
  • ****
Re: Repairing (physically/visually)
« Reply #19 on: 05 Apr 2008, 09:49:22 »
Whether there is a return or not depends on the code that follows the handle I think.  Using "_nul" doesn't actually destroy or block the return, it is more to informally remind you that you are ignoring this return as you have no use for it.  I could have written "_ignoreThis" or "_noReturn" or anything for the same purpose. I use "_nul" because it is a quick easy fit.  Sorry for any confusion.

Offline Rommel92

  • Members
  • *
Re: Repairing (physically/visually)
« Reply #20 on: 05 Apr 2008, 10:07:18 »
Ok, so the "_nul" will handle and returns that might be sent back. In this case, none will be sent.

So it is like Java's:

public void blahBlah()
{

}

where void is the return type.... right?

Code: (add.sqf) [Select]
private ["_a","_b","_c"];
_a = _this select 0;
_b = _this select 1;
_c = _a + _b;
_c

_m = [1,2] execVM "add.sqf";
_m == 3;

Hope that helps, the fact that he put _nul there has nothing to do with the word, it just means... Null, nothing, if you wished to use the return value, you could still use _nul, but most times you wouldn't for easy reading/debugging.

Variable = Return of Operation.
So if:
"_VAR = 1 + 15" then _VAR = 16, not 1 + 15. And if you do variables inside this, "_VAR = _vA + _vB" then _VAR = whatever _vA and _vB equal at that time, say their both 10, _VAR = 20. If _vA or _vB change to say 2, _VAR will still = 20 unless you do the _VAR = _vA + _vB operation again (which would mean _VAR = 4), as it does not store the variables, it stores the RESULT, or the Return of the Operation.

I think I went a bit off topic...
« Last Edit: 05 Apr 2008, 10:12:41 by rommel92 »