1 registered members (AndrewAMD),
1,225
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Were have i gone wrong this time
#241975
12/20/08 16:02
12/20/08 16:02
|
Joined: Nov 2005
Posts: 1,007
jigalypuff
OP
Serious User
|
OP
Serious User
Joined: Nov 2005
Posts: 1,007
|
I am yet again stumped I have a string to show total credits on a text panel
string credit = 10000;
text credit_txt
{
pos_x = 774;
pos_y = 305;
layer = 2;
font lcars2_font;
string = credit;
layer = 1;
}
So far so good, it shows up were i want However when i select a ship i need that to go down so i did the following.
var credits = 10000;
function tile_event()
{
if (bmapno ==1)
{
credits = - 2000;
ent_create(ship_b1, my.x, ship_function); // create / place ship at my.x?
}
if (bmapno ==2)
{
ent_create(ship_b2, my.x, ship_function); // create / place ship at my.x?
}
if (bmapno ==3)
{
ent_create(ship_b3, my.x, ship_function); // create / place ship at my.x?
}
}
Now i have tried to change credits to the string credits_txt but get a read only error. I am stuck as i cannot figure out how to get that 10g number to go down
Why does everyone like dolphins?
Never trust a species which smiles all the time!
|
|
|
Re: Were have i gone wrong this time
[Re: jigalypuff]
#241983
12/20/08 16:38
12/20/08 16:38
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
error = treating STRING as var or visa versa? STTRING (str) functions (C-Script)
STRING credits_s[256]; // 256 may be excessive
var credits_n = 10000;
TEXT credits_t
{
pos_x = 774;
pos_y = 305;
layer = 2;
font lcars2_font;
string = credits_s
layer = 1;
}
// convenience functions
function creditsf_update() {
str_for_num(credits_s, credits_n);
}
function creditsf_add(_n) {
//if (credits_n < 0) {
//credits_n = max(credits_n + _n, 0); // -credits not allowed
//} else {
credits_n += _n;
//}
creditsf_update();
}
function creditsf_set(_n) {
credits_n = _n;
creditsf_update();
}
function tile_event()
{
if (bmapno ==1)
{
//credits = - 2000;
creditsf_set(-2000);
ent_create(ship_b1, my.x, ship_function); // create / place ship at my.x?
}
if (bmapno ==2)
{
ent_create(ship_b2, my.x, ship_function); // create / place ship at my.x?
}
if (bmapno ==3)
{
ent_create(ship_b3, my.x, ship_function); // create / place ship at my.x?
}
}
|
|
|
Re: Were have i gone wrong this time
[Re: testDummy]
#241987
12/20/08 17:00
12/20/08 17:00
|
Joined: Nov 2005
Posts: 1,007
jigalypuff
OP
Serious User
|
OP
Serious User
Joined: Nov 2005
Posts: 1,007
|
sorry man this does not work, the credits panel does not show 10g`s and if i place a ship it comes up with -2000, if i place a different ship (cost 3g`s) it shows -3000, and i can place a lot more than 10g`s worth (i uncommented that part)
Why does everyone like dolphins?
Never trust a species which smiles all the time!
|
|
|
Re: Were have i gone wrong this time
[Re: jigalypuff]
#241993
12/20/08 17:45
12/20/08 17:45
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
Quoting jigalypuff. sorry man this does not work, Twas an example only. Usage is optional (pattern ON).
// maybe try?
function creditsf_add(_n) {
if (_n < 0) {
if ((credits_n + _n) < 0) {
return(0);
}
}
credits_n += _n;
creditsf_update();
return(1);
}
// in main function (or use starter)
function main() {
// level load
creditsf_add(10000);
}
//...
// buy ship code
if (creditsf_add(-shipCost)) {
// can afford
// transaction OK
// add ship
} else {
// come back with more dough captain
}
//...
// put ship back
creditsf_add(shipCost); // refund full cost
...or alternately deal with credits_n directly (or similar) and remember to invoke str_for_num(credits_s, credits_n) (or similar) when appropriate? ...or, create an updating while(1) { wait(1); } loop for credits_n, credits_s (or similar) and update using str_for_num there?
|
|
|
Re: Were have i gone wrong this time
[Re: jigalypuff]
#242020
12/20/08 21:02
12/20/08 21:02
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
Above sample modified. Communication is not 'my' strong suit. Naming schemes may be confusing. naming scheme used in samples: ---credit_s = credit STRING (s) ---credit_n = credit var (n) ---creditf = credit function (f) 'your' choice (naming scheme) original vars from first post in thread
string credit = 10000; // <- can't set string value directly
// must use str functions (look in manual)
STRING credit[256]; // changed
var credits = 10000; // to display on screen, this value should be copied to STRING credit
// ...
// credits was modified?
// convert var to STRING
str_for_num(credit, credits); // converts / copies credits (var) to STRING credit
If credits (var) is modified, and the modification should be shown on screen, the (STRING) value of credits (var) should be copied to credit (STRING) via str_for_num. creditf functions in samples were / are optional example convenience / inconvenience functions. The functions just encapsulate the conversion (var to STRING) (+etc.). STRINGs are modified / assigned values through str functions. So:
string credit = 100; // <- error!?
|
|
|
Re: Were have i gone wrong this time
[Re: testDummy]
#242098
12/21/08 11:57
12/21/08 11:57
|
Joined: Nov 2005
Posts: 1,007
jigalypuff
OP
Serious User
|
OP
Serious User
Joined: Nov 2005
Posts: 1,007
|
yippee `tis working, almost even when i get to zero credits i can still place ships, i have tried proc_kill to stop this function (which shows a bmap of the ship to select) and then allows you to place it on the grid, but i can`t get it to stop
function tile_event()
{
if (bmapno ==1)
{
creditsf_add(-2000);
ent_create(ship_b1, my.x, ship_function); // create / place ship at my.x?
}
if (bmapno ==2)
{
creditsf_add(-3000);
ent_create(ship_b2, my.x, ship_function); // create / place ship at my.x?
}
if (bmapno ==3)
{
creditsf_add(-500);
ent_create(ship_b3, my.x, ship_function); // create / place ship at my.x?
}
}
So the cash goes down but i still can place ships on the grid, i know i need to switch off the above function when credits == 0; but i can`t figure were to put that, everything i have tried seems to fail
Why does everyone like dolphins?
Never trust a species which smiles all the time!
|
|
|
Re: Were have i gone wrong this time
[Re: jigalypuff]
#242128
12/21/08 14:42
12/21/08 14:42
|
Joined: Nov 2005
Posts: 1,007
jigalypuff
OP
Serious User
|
OP
Serious User
Joined: Nov 2005
Posts: 1,007
|
I think i am getting there i tried this
function tile_event()
{
if (bmapno ==1 && credits >0)
{
creditsf_add(-2000);
ent_create(ship_b1, my.x, ship_function); // create / place ship at my.x?
}
if (bmapno ==2 && credits >0)
{
creditsf_add(-3000);
ent_create(ship_b2, my.x, ship_function); // create / place ship at my.x?
}
if (bmapno ==3 && credits >0)
{
creditsf_add(-500);
ent_create(ship_b3, my.x, ship_function); // create / place ship at my.x?
}
}
it almost works, but when selecting ships with different costs it fails, i gat down to say 2g`s i can still add 3g ships as many times as i want. I am missing something quite simple i am sure
Last edited by jigalypuff; 12/21/08 14:44.
Why does everyone like dolphins?
Never trust a species which smiles all the time!
|
|
|
Re: Were have i gone wrong this time
[Re: jigalypuff]
#242136
12/21/08 16:23
12/21/08 16:23
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
function tile_event() {
if (bmapno ==1) {
if (creditsf_add(-2000)) { // transaction would be above 0?
wait(1);
ent_create(ship_b1, my.x, ship_function); // create / place ship at my.x?
goto(fExit);
}
}
if (bmapno ==2) {
if (creditsf_add(-3000)) {
wait(1);
ent_create(ship_b2, my.x, ship_function); // create / place ship at my.x?
goto(fExit);
}
}
if (bmapno ==3) {
if (creditsf_add(-500)) {
wait(1);
ent_create(ship_b3, my.x, ship_function); // create / place ship at my.x?
goto(fExit);
}
}
fExit:
}
(but there is a cleaner way to do that and similar.) creditsf_add and creditsf_update were using credits_n and credits_s. Did 'you' modify the functions so that the variables credits and credit are used instead? For this, use only one set of variables to represent credits: credit_n, credit_s OR credits, credit (Perhaps, 'I' should not have introduced additional variables.)
|
|
|
Re: Were have i gone wrong this time
[Re: testDummy]
#242152
12/21/08 17:46
12/21/08 17:46
|
Joined: Nov 2005
Posts: 1,007
jigalypuff
OP
Serious User
|
OP
Serious User
Joined: Nov 2005
Posts: 1,007
|
Bingo, this works just right man, thank you i was confounded with that Does the function stop running btw? so when ship selection is done and i press me launch game button i can then click on the ships to give them orders?
Why does everyone like dolphins?
Never trust a species which smiles all the time!
|
|
|
|