just another script question

Non-platform specific questions.

just another script question

Postby Goettsch » Tue Sep 24, 2013 5:24 pm

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
Support me and open these links:
http://adf.ly/pZps0 (as many times as you can)
http://VisitsToMoney.com/index.php?refId=470333 (open once)
http://Visitors2Cash.com/ref.php?refId=169224 (open once)
My games:
Kingdoms of... http://adf.ly/pZq5O
Goettsch
 
Posts: 124
Joined: Fri Jun 28, 2013 10:00 pm
Score: 5 Give a positive score

Re: just another script question

Postby skydereign » Tue Sep 24, 2013 6:02 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: just another script question

Postby Goettsch » Tue Sep 24, 2013 6:36 pm

thank you
Support me and open these links:
http://adf.ly/pZps0 (as many times as you can)
http://VisitsToMoney.com/index.php?refId=470333 (open once)
http://Visitors2Cash.com/ref.php?refId=169224 (open once)
My games:
Kingdoms of... http://adf.ly/pZq5O
Goettsch
 
Posts: 124
Joined: Fri Jun 28, 2013 10:00 pm
Score: 5 Give a positive score

Re: just another script question

Postby Goettsch » Wed Sep 25, 2013 6:33 pm

it is possible to save current animation,if an actor is created or not,a text actor using saveVars and loadVars?
Support me and open these links:
http://adf.ly/pZps0 (as many times as you can)
http://VisitsToMoney.com/index.php?refId=470333 (open once)
http://Visitors2Cash.com/ref.php?refId=169224 (open once)
My games:
Kingdoms of... http://adf.ly/pZq5O
Goettsch
 
Posts: 124
Joined: Fri Jun 28, 2013 10:00 pm
Score: 5 Give a positive score

Re: just another script question

Postby skydereign » Wed Sep 25, 2013 6:39 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: just another script question

Postby Goettsch » Wed Sep 25, 2013 6:54 pm

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
Support me and open these links:
http://adf.ly/pZps0 (as many times as you can)
http://VisitsToMoney.com/index.php?refId=470333 (open once)
http://Visitors2Cash.com/ref.php?refId=169224 (open once)
My games:
Kingdoms of... http://adf.ly/pZq5O
Goettsch
 
Posts: 124
Joined: Fri Jun 28, 2013 10:00 pm
Score: 5 Give a positive score

Re: just another script question

Postby Goettsch » Fri Sep 27, 2013 10:30 pm

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'
Support me and open these links:
http://adf.ly/pZps0 (as many times as you can)
http://VisitsToMoney.com/index.php?refId=470333 (open once)
http://Visitors2Cash.com/ref.php?refId=169224 (open once)
My games:
Kingdoms of... http://adf.ly/pZq5O
Goettsch
 
Posts: 124
Joined: Fri Jun 28, 2013 10:00 pm
Score: 5 Give a positive score

Re: just another script question

Postby skydereign » Sat Sep 28, 2013 12:02 am

That's because you need to use NO_CHANGE, not "NO_CHANGE".
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: just another script question

Postby Goettsch » Sat Sep 28, 2013 10:29 pm

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
Support me and open these links:
http://adf.ly/pZps0 (as many times as you can)
http://VisitsToMoney.com/index.php?refId=470333 (open once)
http://Visitors2Cash.com/ref.php?refId=169224 (open once)
My games:
Kingdoms of... http://adf.ly/pZq5O
Goettsch
 
Posts: 124
Joined: Fri Jun 28, 2013 10:00 pm
Score: 5 Give a positive score

Re: just another script question

Postby skydereign » Sun Sep 29, 2013 6:22 pm

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?
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: just another script question

Postby Goettsch » Sun Sep 29, 2013 6:40 pm

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
Support me and open these links:
http://adf.ly/pZps0 (as many times as you can)
http://VisitsToMoney.com/index.php?refId=470333 (open once)
http://Visitors2Cash.com/ref.php?refId=169224 (open once)
My games:
Kingdoms of... http://adf.ly/pZq5O
Goettsch
 
Posts: 124
Joined: Fri Jun 28, 2013 10:00 pm
Score: 5 Give a positive score

Re: just another script question

Postby skydereign » Sun Sep 29, 2013 6:52 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: just another script question

Postby Goettsch » Sun Sep 29, 2013 7:08 pm

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?
Support me and open these links:
http://adf.ly/pZps0 (as many times as you can)
http://VisitsToMoney.com/index.php?refId=470333 (open once)
http://Visitors2Cash.com/ref.php?refId=169224 (open once)
My games:
Kingdoms of... http://adf.ly/pZq5O
Goettsch
 
Posts: 124
Joined: Fri Jun 28, 2013 10:00 pm
Score: 5 Give a positive score

Re: just another script question

Postby skydereign » Sun Sep 29, 2013 8:27 pm

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
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: just another script question

Postby Goettsch » Tue Oct 01, 2013 6:46 pm

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
Support me and open these links:
http://adf.ly/pZps0 (as many times as you can)
http://VisitsToMoney.com/index.php?refId=470333 (open once)
http://Visitors2Cash.com/ref.php?refId=169224 (open once)
My games:
Kingdoms of... http://adf.ly/pZq5O
Goettsch
 
Posts: 124
Joined: Fri Jun 28, 2013 10:00 pm
Score: 5 Give a positive score

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron