Page 1 of 2

just another script question

PostPosted: Tue Sep 24, 2013 5:24 pm
by Goettsch
I am working on a strategy game,i have a variable named food and another variable named foodproduction,what i want but don't know how to do is:

every 1 minute food=food+foodproduction

Re: just another script question

PostPosted: Tue Sep 24, 2013 6:02 pm
by skydereign
You know the code, and you know when you want the code to trigger. The trick is to know what event will trigger during those times. You could put some code in the view's draw event, and only trigger it once every second. But you can also create a timer event. Currently the CreateTimer version is a little harder to pause, if you plan to allow players to stop the game.
view -> Draw Actor -> Script Editor
Code: Select all
food_timer++;
if(food_timer>=30) // one second
{
    food_timer = 0; // set it back to 0
    food += foodproduction;
}


Or this, making sure the food timer is infinite, and you call CreateTimer to start it.
view -> Timer (food) -> Script Editor
Code: Select all
food += foodproduction.

Re: just another script question

PostPosted: Tue Sep 24, 2013 6:36 pm
by Goettsch
thank you

Re: just another script question

PostPosted: Wed Sep 25, 2013 6:33 pm
by Goettsch
it is possible to save current animation,if an actor is created or not,a text actor using saveVars and loadVars?

Re: just another script question

PostPosted: Wed Sep 25, 2013 6:39 pm
by skydereign
Current animation of an actor is stored by the animindex variable. If for instance you want to save the player's current animindex, you can create a variable with the gui and put it in a savegroup. That way you can just do this.
Code: Select all
player_anim = player.animindex;
saveVars("player_vars", "player_vars");

The same can be done to save the text variable of text actors.

Re: just another script question

PostPosted: Wed Sep 25, 2013 6:54 pm
by Goettsch
thanks,for a strategy game i have to save a lot of things
the game is like a browser strategy game(Travian,Grepolis,Godgame Empire) but singleplayer,when i will finish the save system and building system i will relase a beta to know how to improve it

Re: just another script question

PostPosted: Fri Sep 27, 2013 10:30 pm
by Goettsch
when i use this cede:

Code: Select all
if(vfood==100&&vstone==200)
{
   ChangeAnimation("bcave", "cave_entrance.svg_", "NO_CHANGE");
}


I get this error: Incompatible types :cannot convert from ' const* char ' to 'int'

Re: just another script question

PostPosted: Sat Sep 28, 2013 12:02 am
by skydereign
That's because you need to use NO_CHANGE, not "NO_CHANGE".

Re: just another script question

PostPosted: Sat Sep 28, 2013 10:29 pm
by Goettsch
skydereign wrote:Current animation of an actor is stored by the animindex variable. If for instance you want to save the player's current animindex, you can create a variable with the gui and put it in a savegroup. That way you can just do this.
Code: Select all
player_anim = player.animindex;
saveVars("player_vars", "player_vars");

The same can be done to save the text variable of text actors.


i should make something similar to this??

Code: Select all
atownhall = btownhall.animindex; //atownhall is the variable saved in buildings group,btownhall is the buildings with 2 animations(one empty,one with the buildings)
afarm = bfarm.animindex;
saveVars("citystatus.kng", "buildings");


but it doesn't work,i don't get any error messages

Re: just another script question

PostPosted: Sun Sep 29, 2013 6:22 pm
by skydereign
Are the btownhall and bfarm actors cloned? If so that will cause problems, as it will only save one of the clones. Also, what is your loading code look like?

Re: just another script question

PostPosted: Sun Sep 29, 2013 6:40 pm
by Goettsch
no,they aren't cloned

i have 2 versions for saving and loading,the loading code with arrays is:

Code: Select all
loadVars("citystatus.kng", "production");
vfood=resources[0];
vfood=resources[1];
vfood=resources[2];
foodproduction=production[0];
woodproduction=production[1];
stoneproduction=production[2];

loadVars("citystatus.kng", "buildings");
btownhall.animindex=buildings[0];
bfarm.animindex=buildings[1];


and the loading code with variables uses atownhall and afarm

the first part with vfood,foodproduction ecc works,the part with buildings no

Re: just another script question

PostPosted: Sun Sep 29, 2013 6:52 pm
by skydereign
Ok, so there's your problem. animindex is a read only variable, which means you can't actually change its value. You'll need to use ChangeAnimation to set it properly. This is a little tricky, as currently the getAnimName function doesn't support clone targeting. To get around this, I personally would use an activation event, or store the variable as the animation name instead. If you store the animation name, you can just use it for the ChangeAnimation function.

Re: just another script question

PostPosted: Sun Sep 29, 2013 7:08 pm
by Goettsch
skydereign wrote: store the variable as the animation name instead. If you store the animation name, you can just use it for the ChangeAnimation function.

ok,i think i will use this,i have the buildings,each building have an animation named townhal.svg,farm.svg ecc and an animation named empty.
how should look the save code?

Re: just another script question

PostPosted: Sun Sep 29, 2013 8:27 pm
by skydereign
Actually to get the animation name dynamically, you'll need to use getAnimName to get the value to store. Therefore I suggest using the SendEvent function. http://game-editor.com/forum/viewtopic.php?f=1&t=12585&p=89665&#p89665

Re: just another script question

PostPosted: Tue Oct 01, 2013 6:46 pm
by Goettsch
I found another way,using variables but now when i try to save in game i get this error

WRITE attempted beyond allowed access area